const
	maxn = 2000;
	maxm = 10000;
var
	n, m, s, pmax, i, j: longint;
	src, dst, wei: array [1..maxm] of longint;
	who: array [1..maxn] of char;
	str: array [1..maxn] of longint;
	p: array [1..maxn] of longint;

	pvr, pv: array [1..maxn] of longint;
	per, pe: array [1..maxm] of longint;
begin
	randseed := 19273001;

	n := 2000;
	m := 10000;

	s := random(n) + 1;

	pmax := 99000;

	for i := 1 to n do begin
		p[i] := random(pmax + 1);
		who[i] := char(ord('A') + random(2));
	end;
    
    for i := 1 to n do begin
    	src[i] := i;
    	dst[i] := random(n) + 1;
    	wei[i] := p[dst[i]] - p[src[i]] + random(2);
    	str[src[i]] := i;
    end;

    for i := n + 1 to m do begin
    	src[i] := random(n) + 1;
    	dst[i] := random(n) + 1;
    	wei[i] := p[dst[i]] - p[src[i]] + random(2);
    	if (random(20) = 0) then
    		str[src[i]] := 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 m do begin
    	j := random(i) + 1;
    	pe[i] := pe[j];
    	pe[j] := i;
    end;
    for i := 1 to n do begin
    	pvr[pv[i]] := i;
    end;
    for i := 1 to m do begin
    	per[pe[i]] := i;
    end;

    writeln(n, ' ', m);
    for i := 1 to n do begin
    	write(who[pvr[i]]);
    end;             
    writeln;
    writeln(s);
    for i := 1 to m do begin
    	writeln(pv[src[per[i]]], ' ', pv[dst[per[i]]], ' ', wei[per[i]]);
    end;
    for i := 1 to n do begin
    	if (who[pvr[i]] = 'A') then
    		write(pe[str[pvr[i]]])
    	else
    		write(0);
    	if (i < n) then
    		write(' ');
    end;
    writeln;
end.