var
	m, n: longint;
	x, y: array [1..100000] of longint;
	key: array [1..200000] of longint;
	pv, pvr: array [1..20000] of longint;
	pe: array [1..100000] of longint;
	i, j: longint;

	head: array [0..262143] of longint;
	next, v1, v2: array [1..200000] of longint;
	e: longint;

	he: array [1..20000] of longint;
	dse: array [1..200000] of longint;
	ind: array [1..200000] of longint;
	nxe: array [1..200000] of longint;

	vis: array [1..20000] of boolean;

function hash(u, v: longint): longint;
begin
	hash := (u * 31 + v) mod 262144;
end;

procedure add(u, v, i: longint);
var
	h: longint;
begin
	h := hash(u, v);
	inc(e);
	next[e] := head[h];
	v1[e] := u;
	v2[e] := v;
	head[h] := e;

	dse[e] := v;
	ind[e] := i;
	nxe[e] := he[u];
	he[u] := e;
end;

function exists(u, v: longint): boolean;
var
	j, h: longint;
begin
	exists := true;

	h := hash(u, v);
	j := head[h];
	while (j <> 0) do begin
		if (v1[j] = u) and (v2[j] = v) then begin
			exit;
		end;

		j := next[j];
	end;

	exists := false;
end;

procedure dfs(x: longint);
var
	j: longint;
begin
	vis[x] := true;
	j := he[x];
	while j <> 0 do begin
		if vis[dse[j]] then begin
			if key[ind[j]] = 0 then
				key[ind[j]] := 1
		end else begin
			key[ind[j]] := 2;
			dfs(dse[j]);
		end;
		j := nxe[j];
	end;
end;


begin
	randseed := 9273047;

	n := 5;
	m := 7;

	for i := 1 to m do begin
		repeat
    		x[i] := random(n) + 1;
    		y[i] := random(n) + 1;
    	until (x[i] <> y[i]) and not exists(x[i], y[i]) and not exists(y[i], x[i]);
    	add(x[i], y[i], i);
    	add(y[i], x[i], i);
	end;

	for i := 1 to m do begin
		j := random(i) + 1;
		pe[i] := pe[j];
		pe[j] := i;
	end;

	for i := 1 to n do begin
		j := random(i) + 1;
		pv[i] := pv[j];
		pv[j] := i;
	end;

	for i := 1 to n do begin
		pvr[pv[i]] := i;
	end;

	dfs(pvr[1]);

	writeln(n, ' ', m);
	for i := 1 to m do begin
		if random(2) = 0 then
			writeln(pv[x[pe[i]]], ' ', pv[y[pe[i]]], ' ', key[pe[i]] - 1)
		else
			writeln(pv[y[pe[i]]], ' ', pv[x[pe[i]]], ' ', key[pe[i]] - 1);
	end;
end.