#include<iostream>
#include<string>
using namespace std;
int main()
{
string x, y;
cin >> x;
cin >> y;
int s = 1, t = 1;
for (int i = 0; i < x.length(); i++)
{
s = s*(x[i] - 64);
}
for (int i = 0; i < y.length(); i++)
{
t = t*(x[i] - 64);
}
if (s % 47 == t % 47)
cout << "GO";
else
cout << "STAY";
}