#include<bits/stdc++.h>
using namespace std;
int main(){
char g[10],w[10];
cin>>g>>w;
if(((g[0]-64)*(g[1]-64)*(g[2]-64)*(g[3]-64)*(g[4]-64)*(g[5]-64))%47==((w[0]-64)*(w[1]-64)*(w[2]-64)*(w[3]-64)*(w[4]-64)*(w[5]-64))%47)
cout<<"GO";
else
cout<<"STAY";
return 0;
}