type Tab = record
						a, b : longint;
					end;

type TTeam = record
							name : string;
							pts : longint;
							g_won, g_tie, g_lost : longint;
							score : Tab;
							match :  array[1..80]of Tab;
							match_pl : array[1..80]of boolean;
							ok : boolean;
						end;

var Teams : array[1..80]of TTeam;

var N, M : longint;
		i, j, k, w, w_i, w_m_won, w_m_tie, w_m_lost, w_matches, w_score, w_pts : longint;
		ln : string;
		t1, t2 : longint;
		maxpts : longint;
		
label zac;
		
function GetTeam(var s : string; var c : longint) : longint;
var i : longint;
		tn : string;
begin
	c := pos(' ', s);
	tn := copy(s, 1, c-1);
	for i := 1 to 80 do
		if(Teams[i].name = tn)then break;
	GetTeam := i;
end;


procedure write_line;
var i : integer;
begin
	write('+');
	for i := 1 to w do
		write('-');
	write('+');
	for i := 1 to N do
		write('---+');
	writeln;
end;


procedure WriteEx(s : string; nc : integer);
var i : integer;
begin
	write(s);
	for i := length(s)+1 to nc do
		write(' ');
end;


function numlen(num : longint) : longint;
var r : longint;
begin
		r := 1;
		while(num >= 10)do begin
			r := r + 1;
			num := num div 10;
		end;
		numlen := r;
end;


procedure WriteExNum(num : longint; nc : integer);
var i : integer;
begin
	for i := numlen(num)+1 to nc do
		write(' ');
	write(num);
end;
		
		
begin
zac:
	i := 0;
	j := 0;
	k := 0;
	w := 0;
	w_i := 0;
	w_m_won := 0;
	w_m_tie := 0;
	w_m_lost := 0;
	w_matches := 0;
	w_score := 0;
	w_pts := 0;
	ln := '';
	t1 := 0;
  t2 := 0;
  for i := 1 to 80 do
	begin
		with Teams[i] do begin
			name := '';
			pts := 0;
			g_won := 0;
			g_tie := 0;
			g_lost := 0;
			score.a := 0; score.b := 0;
			for j := 1 to 80 do begin match[j].a := 0; match[j].b := 0; end;
			for j := 1 to 80 do match_pl[j] := false;
			ok := false
		end;
	end;
	
	readln(N);
	if(N = 0)then exit;
	for i := 1 to N do
		readln(Teams[i].name);
		
	readln(M);
	for i := 1 to M do
	begin
		readln(ln);
		t1 := GetTeam(ln, j);
		ln := copy(ln, j+3);
		t2 := GetTeam(ln, j);
		ln := copy(ln, j+1);
		with Teams[t1].match[t2] do
		begin
			a := ord(ln[1]) - ord('0');
			b := ord(ln[3]) - ord('0');
			Teams[t1].match_pl[t2] := true;
			
			Teams[t1].score.a := Teams[t1].score.a + a;
			Teams[t1].score.b := Teams[t1].score.b + b;
			Teams[t2].score.a := Teams[t2].score.a + b;
			Teams[t2].score.b := Teams[t2].score.b + a;
			if(a > b)then
			begin
				Teams[t1].pts := Teams[t1].pts + 3;
				inc(Teams[t1].g_won);
				inc(Teams[t2].g_lost);
			end else if(a < b)then
			begin
				Teams[t2].pts := Teams[t2].pts + 3;
				inc(Teams[t2].g_won);
				inc(Teams[t1].g_lost);
			end else
			begin
				Teams[t1].pts := Teams[t1].pts + 1;
				inc(Teams[t1].g_tie);
				Teams[t2].pts := Teams[t2].pts + 1;
				inc(Teams[t2].g_tie);			
			end;
		end;
	end;
	
{vystup}

	writeln('RESULTS:');
	for i := 1 to N do
		w := max(length(Teams[i].name), w);
	write_line;
	write('|');
	for i := 1 to w do write(' ');
	for i := 1 to N do
	begin
		write('|', copy(Teams[i].name, 1, 3));
		if(length(Teams[i].name) = 2)then write(' ')
		else if(length(Teams[i].name) = 1)then write('  ');
	end;
	writeln('|');
	for i := 1 to N do
	begin
		write_line;
		write('|');
		writeex(Teams[i].name, w);
		write('|');
		for j := 1 to N do
		begin
		  if(i = j)then
				write(' X ')
			else if(Teams[i].match_pl[j])then
				write(Teams[i].match[j].a, ':', Teams[i].match[j].b)
			else
				write('   ');
			write('|');
		end;
		writeln;
	end;
	write_line;
	writeln;
	writeln('STANDINGS:');
	writeln('----------');
	
	for i := 1 to N do
	begin
		with Teams[i] do begin
			w_matches := max(w_matches, numlen(g_won+g_tie+g_lost));
			w_m_won := max(w_m_won, numlen(g_won));
			w_m_tie := max(w_m_tie, numlen(g_tie));
			w_m_lost := max(w_m_won, numlen(g_lost));
			w_score := max(w_score, numlen(score.a) + 1 + numlen(score.b));
			w_pts := max(w_pts, numlen(pts));
		end;
	end;
	if(N < 10)then w_i := 3
		else w_i := 4;
	
	for i := N downto 1 do
	begin
		k := 0;
		for j := 1 to N do
		begin
			if(Teams[j].ok)then continue;
			if(k = 0)then begin
		 		k := j;
		 		continue;
		 	end;
			if(Teams[k].pts > Teams[j].pts)then continue
			else if(Teams[k].pts = Teams[j].pts)then begin
				if((Teams[k].score.a - Teams[k].score.b) > (Teams[j].score.a - Teams[j].score.b))then continue
				else if((Teams[k].score.a - Teams[k].score.b) = (Teams[j].score.a - Teams[j].score.b))then begin
					if(Teams[k].score.a > Teams[j].score.a)then continue
					else if(Teams[k].score.a = Teams[j].score.a)then
						if(Teams[k].g_won > Teams[j].g_won)then continue;
				end;
			end;
			k := j;
		end;
		write(N-i+1, '. ');
		if(N-i+1 < 10)and(w_i = 4)then write(' ');
		with(Teams[k])do begin		
			writeex(name, w+1);
			writeexnum(g_won+g_tie+g_lost, w_matches); write(' ');
			writeexnum(g_won, w_m_won); write(' ');
			writeexnum(g_tie, w_m_tie); write(' ');
			writeexnum(g_lost, w_m_lost); write(' ');
			for j := numlen(score.a) + numlen(score.b)+2 to w_score do write(' ');
			write(score.a, ':', score.b); write(' ');
			writeexnum(pts, w_pts);
			ok := true;
			writeln;
		end;
	end;
			{writeln;}
	goto zac;
end.