// https://www.luogu.com.cn/problem/P1200
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a, b;
int c = 1, d = 1, i;
cin >> a >> b;
for (i = 0; i < a.size(); i++)
{
c *= a[i] - 'A' + 1;
}
for (i = 0; i < b.size(); i++)
{
d *= b[i] - 'A' + 1;
}
c %= 47;
d %= 47;
if (c == d)
{
cout << "GO";
}
else
{
cout << "STAY";
}
return 0;
}