var s,t:string;
m,n:longint;
i:longint;
begin
readln(s,t);
m:=1;n:=1;
for i:=1 to length(s) do
if( s[i]>='A') and (s[i]<='Z') then
m:=m*(ord(s[i])-ord('A')+1);
for i:=1 to length(t) do
if (t[i]>='A' ) and (t[i]<'Z') then
n:=n*(ord(t[i])-ord('A')+1);
if (m mod 47)=(n mod 47) then writeln('GO')
else writeln('STAY');
end.