#pragma comment(linker, "/STACK:16777216")

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long LL;

const int m = 8;
const int n = 16;
const int MAX_X = 1048576;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

char* a;
char* b;
char* temp[100];
int was[n][m+2];
int x[MAX_X];

/*
bool operator< (const ii& a, const ii& b) {
	return a.first + 100000*a.second < b.first + 100000*b.second;
}
*/

void calc_xs(int x0) {
	x[0] = x0;
	for (int i = 1; i < MAX_X; i++) {
		x[i] = (int)((x[i - 1] * 17235617LL + 4311271) % 87465851);
	}
}

bool good(int x, int y) {
	return 0 <= x && x < n && 0 <= y && y < m;
}

inline int ge(char* a, int x, int y) {
	return a[x*m + y];
}

inline void se(char* a, int x, int y, int z) {
	a[x*m + y] = z;
}

// in component: (c, black)
ii dfs(int iter, int c, int i, int j, bool go_black = true) {
	if (was[i][j]) return ii(0,0);
	was[i][j] = iter;
	ii ans = ii(ge(a,i,j) == c, ge(a,i,j) == 6);
	forn(d, 4) {
		int x = i + dx[d], y = j + dy[d];
		if (!good(x, y)) continue;
		if (ge(a,x,y) == c || (ge(a,x,y) == 6 && go_black)) {
			if (ge(a,i,j) == 6 && ge(a,x,y) == c) continue;
			ii z = dfs(iter, c, i + dx[d], j + dy[d], go_black);
			ans.first += z.first;
			ans.second += z.second;
		}
	}
	return ans;
}

void destroy(int iter, int i, int j) {
	if (was[i][j] != iter) return;
	was[i][j] = -1;
	forn(d, 4) {
		int x = i + dx[d], y = j + dy[d];
		if (!good(x, y)) continue;
		destroy(iter, x, y);
	}
}

int bonus_lav(int x) {
	if (x <= 1) return 0;
	if (x == 2) return 3;
	if (x == 3) return 6;
	if (x == 4) return 12;
	if (x == 5) return 24;
	if (x == 6) return 50;
	return 100;
}

struct turn_score {
	int bonus;
	int func;
	int height;
	turn_score(int _bonus, int _func, int _height): bonus(_bonus), func(_func), height(_height) { }
	turn_score(int _invalid): bonus(-1000000), height(0) { }
};

bool operator< (const turn_score& a, const turn_score& b) {
	if (a.bonus < b.bonus) return true;
	if (a.bonus > b.bonus) return false;
	if (a.func < b.func) return true;
	if (a.func > b.func) return false;
	if (a.height < b.height) return true;
	if (a.height > b.height) return false;
	return false;
}

bool operator> (const turn_score& a, const turn_score& b) { return b < a; }

turn_score go(int tt, int turn) {
	int s = tt >> 2, r = tt & 3;
	int x1 = 0, y1 = s;
	if (r == 3) x1 = 1;
	int x2 = x1 + dx[r], y2 = y1 + dy[r];
	int c1 = x[2*turn-2] % 5 + 1;
	int c2 = x[2*turn-1] % 5 + 1;
	if (!good(x1, y1) || !good(x2, y2)) return turn_score(-1);
	if (ge(a, x1, y1) || ge(a, x2, y2)) return turn_score(-1);
	if (r == 3) swap(x1, x2), swap(y1, y2), swap(c1, c2);
	while (x1 + 1 < n && !ge(a, x1 + 1, y1)) x1++;
	se(a, x1, y1, c1);
	while (x2 + 1 < n && !ge(a, x2 + 1, y2)) x2++;
	se(a, x2, y2, c2);
	
	vector<vii> lavina;
	
	while (1) {
		memset(was, 0, sizeof was);
		int iter = 1;
		vii destroyed;
		forn(i, n) forn(j, m) if (!was[i][j] && ge(a,i,j) != 6 && ge(a,i,j)) {
			ii d = dfs(iter, ge(a, i, j), i, j);
			if (d.first >= 4) {
				destroy(iter, i, j);
				destroyed.push_back(d);
			}
			iter++;
		}
		if (destroyed.empty()) break;
		lavina.push_back(destroyed);
		forn(i, n) forn(j, m) if (was[i][j] == -1) se(a,i,j,0);
		forn(j, m) {
			int p = n;
			for (int i = n - 1; i >= 0; i--) if (ge(a,i,j)) {
				p--;
				se(a,p,j,ge(a,i,j));
			}
			while (--p>=0) se(a,p,j,0);
		}
	}
	
	int ans = bonus_lav(lavina.size());
	for (vector<vii>::iterator it = lavina.begin(); it != lavina.end(); ++it) {
		vii& z = *it;
		for (vii::iterator jt = z.begin(); jt != z.end(); ++jt) {
			ii& u = *jt;
			ans += u.first - 1;
		}
		ans -= 2;
	}
	
	memset(was, 0, sizeof was);
	int func = 0;
	forn(i, n) forn(j, m) if (!was[i][j] && ge(a,i,j) != 6 && ge(a,i,j)) {
		int coeff = 1;
		forn(dd, 4) {
			int x = i + dx[dd], y = j + dy[dd];
			if (!good(x, y)) continue;
			if (!ge(a, x, y)) { coeff = 10; break; }
		}
		ii d = dfs(1, ge(a,i,j), i, j, true);
		int z = d.first + d.second;
		int add = 0;
		if (d.first == 2) add = z;
		if (d.first == 3) add = 50 + z;
		func += coeff * add;
	}
	
	int mincell = n - 1;
	forn(i, n) forn(j, m) if (ge(a,i,j)) mincell = min(mincell, i);
	return turn_score(ans, func, mincell);
}

struct game_score {
	int bonus_sum;
	int func_sum;
	int height_last;
	game_score(int Bonus_sum, int Func_sum, int Height_last): bonus_sum(Bonus_sum), func_sum(Func_sum), height_last(Height_last) { }
	game_score(const turn_score& t): bonus_sum(t.bonus), func_sum(t.func), height_last(t.height) { }
	game_score(const turn_score& a, const game_score& b): bonus_sum(a.bonus + b.bonus_sum / 2), func_sum(a.func + b.func_sum / 2), height_last(b.height_last) { }
};

bool operator< (const game_score& a, const game_score& b) {
	if (a.bonus_sum < b.bonus_sum) return true;
	if (a.bonus_sum > b.bonus_sum) return false;
	if (a.func_sum < b.func_sum) return true;
	if (a.func_sum > b.func_sum) return false;
	if (a.height_last < b.height_last) return true;
	if (a.height_last > b.height_last) return false;
	return false;
}

bool operator> (const game_score& a, const game_score& b) { return b < a; }

game_score go_turn(int left, int turn, int tt) {
	turn_score z = go(tt, turn);
	if (left == 0) return game_score(z);
	vector< pair<turn_score, int> > turns;
	forn(t, 32) {
		forn(i, n) forn(j, m) se(temp[left], i, j, ge(a, i, j));
		turn_score u = go(t, turn);
		forn(i, n) forn(j, m) se(a, i, j, ge(temp[left], i, j));
		if (u.bonus >= 0) turns.push_back(make_pair(u, t));
	}
	sort(turns.begin(), turns.end(), greater< pair<turn_score, int> >());
	game_score best = game_score(-1000, 0, 0);
	for (int i = 0, nn = (int)turns.size(); i < 8 && i < nn; i++) {
		int t = turns[i].second;
		forn(i, n) forn(j, m) se(temp[left], i, j, ge(a, i, j));
		game_score u = go_turn(left - 1, turn + 1, t);
		if (u > best) best = u;
		forn(i, n) forn(j, m) se(a, i, j, ge(temp[left], i, j));
	}
	return game_score(z, best);
}


int main() {
	srand((unsigned)time(0));
	a = new char[n*m];
	b = new char[n*m];
	forn(i, 100) temp[i] = new char[n*m];
	for(int turn = 0 ; ; ++turn)
	{
		char str[100];
		scanf("%s",str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			int x0;
			scanf("%d", &x0);
			printf("GodKing\n");
			calc_xs(x0);
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {
			forn(i, n) {
				scanf("%s", str);
				forn(j, m) if (str[j] == '.') se(a, i, j, 0);
					else if (str[j] == '*') se(a, i, j, 6);
					else se(a, i, j, str[j] - '0');
			}
			forn(i, n) {
				scanf("%s", str);
				forn(j, m) if (str[j] == '.') se(b, i, j, 0);
					else if (str[j] == '*') se(b, i, j, 6);
					else se(b, i, j, str[j] - '0');
			}
			
			const int REC_DEPTH = 3;
			
			game_score best = game_score(-1000, 0, 0);
			int bestt = 0;
			forn(t, 32) {
				forn(i, n) forn(j, m) se(temp[0], i, j, ge(a, i, j));
				game_score cur = go_turn(REC_DEPTH - 1, turn, t);
				forn(i, n) forn(j, m) se(a, i, j, ge(temp[0], i, j));
				if (cur > best) best = cur, bestt = t;
			}
			
			int s = bestt >> 2, r = bestt & 3;
			if (r == 2) s--;
			printf("%d %d\n", s, r);
			fflush(stdout);
		}
	}

	return 0;
}
