program check;

uses
	testlib, sysutils;

const
	maxm = 30000;

var
	ja, pa: string;
	i, m, n: longint;
	s: string;
	a, b: array [1..maxm] of longint;

begin
	ja := uppercase(trim(ans.readstring));
	pa := uppercase(trim(ouf.readstring));

	if pa = 'IMPOSSIBLE' then begin
		if ja = 'IMPOSSIBLE' then
			quit(_ok, 'IMPOSSIBLE');
		quit(_wa, 'Impossible unexpected');
	end;

	n := inf.readlongint;
	m := inf.readlongint;
	inf.seekeof;
	s := inf.readstring;
	for i := 1 to m do begin
		a[i] := inf.readlongint;
		b[i] := inf.readlongint;
	end;

	if length(pa) <> n then
		quit(_wa, 'Wrong answer length');
	for i := 1 to n do begin
		if not (pa[i] in ['R', 'G', 'B']) then
			quit(_wa, 'Invalid character in the answer');
		if pa[i] = s[i] then
			quit(_wa, format('Same color of vertex %d', [i]));
	end;

	for i := 1 to m do begin
		if pa[a[i]] = pa[b[i]] then
			quit(_wa, format('Circles %d and %d are connected but have the same color', [a[i], b[i]]));
	end;

	if ja = 'IMPOSSIBLE' then
		quit(_fail, 'Jury thought it was impossible');

	quit(_ok, '');
end.