int main()
{
int n[4] = { 1,1 };
int letter[256] = {};
for (int i = 0; i < 26; i++) letter['A' + i] = i + 1;
for (int i = 0; i < 2; i++) {
char word[12];
for (int j = 0; j < 12; j++) word[j] = '0';
scanf("%s", word);
for (int j = 0; j < 6; j++) {
if (word[j] == '0') break;
n[i] *= letter[word[j]];
}
}
if ((n[0] % 47) == (n[1] % 47)) printf("GO");
else printf("STAY");
return 0;
}