#include <cstring>
#include <deque>
#include <cctype>
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;
int const H = 16, W = 8;

int bonus[H*W + 1] = {0, 0, 3, 6, 12, 24, 50, 100};

int next(int x)
{
	return ((long long)x * 17235617ll + 4311271ll) % 87465851ll;
}

const int INF1=10000;
char w[H+2][W+2];
FILE* journal;

struct field {
	char s[H+2][W+2];

	char curcolor;

	field() {
		memset(s, 0, sizeof s);
	}
	field(const field & a) {
		memcpy(s, a.s, sizeof s);
	}
	field(char a[H+2][W+2]){
		memcpy(s, a, sizeof s);
	}

	int dfs(int x, int y) {
		if (w[x][y] != 0 || s[x][y] != curcolor) 
			return 0;
		w[x][y] = 1;
		return 1 + dfs(x-1, y) + dfs(x+1, y) + dfs(x, y-1) + dfs(x, y+1);	
	}
	int DFS(int x, int y) {
		curcolor = s[x][y];
		return dfs(x, y);
	}
	int mark(int x, int y) {
		if (w[x][y] != 1 || s[x][y] != curcolor) 
			return 0;
		w[x][y] = 2, s[x][y] = '.';
		return mark(x-1, y) + mark(x+1, y) + mark(x, y-1) + mark(x, y+1);	
	}
	int MARK(int x, int y) {
		curcolor = s[x][y];
		return mark(x, y);
	}
	int lavina_step() {
		memset(w, 0, sizeof w);
		int f = -2, cr;
		for (int i=1; i<=H; i++)
			for (int j=1; j<=W; j++)
				if (!w[i][j] && isdigit(s[i][j]) && (cr = DFS(i, j)) >= 4)
					MARK(i, j), f += cr - 1;
		for (int i=1; i<=H; i++)
			for (int j=1; j<=W; j++)
				if (s[i][j] == '*' || (w[i-1][j] == 2 || w[i+1][j] == 2 || w[i][j-1] == 2 || w[i][j+1] == 2))
					w[i][j] = 2, s[i][j] = '.';
		for (int j=1; j<=W; j++)
			for (int i=2; i<=H; i++)
				if (w[i][j] == 2 && w[i-1][j] != 2) {
					swap(w[i][j], w[i-1][j]);
					swap(s[i][j], s[i-1][j]);
				}
	   	return max(0, f);
	}

	int lavina() {
		int res = 0, nstep = 0, cur;
		while (cur = lavina_step()) 
			++nstep, res += cur;
		return res + bonus[nstep];
	}
	
	bool pull(int pos, char c)
	{	
		if (pos < 1 || pos > W)
			return false;

		for(int i = H; i >= 1; i--)
		if (s[i][pos] == '.')
		{
			s[i][pos] = c;
			return true;
		}
		return false;
	}
	
	void unpull(int pos) {
		for (int i = 1; i<=H; i++)
			if (s[i][pos]!='.') {
				s[i][pos]= '.';
				return;
			}
   	}
		

	int move(int pos, int r, int& x)
	{
		char c[2];
		c[0] = x % 5 + '1';
		x = next(x);
		c[1] = x % 5 + '1';
		x = next(x);

		bool can = 1;
		if (r == 0)
		{
			can = can && pull(pos, c[0]);
			if (!can) return -INF1;
			can = can && pull(pos+1, c[1]);
			if (!can) unpull(pos);
		}
		else
		if (r == 2)
		{
			can = can && pull(pos, c[0]); 
			if (!can) return -INF1;
			can = can && pull(pos-1, c[1]);
			if (!can) unpull(pos);
		}
		else
		if (r == 1)
		{
			can = can && pull(pos, c[1]); 
			if (!can) return -INF1;
			can = can && pull(pos, c[0]);
			if (!can) unpull(pos);
		}
		else
		if (r == 3)
		{
			can = can && pull(pos, c[0]); 
			if (!can) return -INF1;
			can = can && pull(pos, c[1]);
			if (!can) unpull(pos);
		}

		if (!can)
			return -INF1;

		return lavina();

//		return true;
	}
	int getH(){
		int i,j;
		for(i=1;i<=H;i++)
			for(j=1;j<=W;j++)
				if(s[i][j]!='.')
					return H-i+1;
		return 0;
	}	
	int moveAll(vector< pair<int, int> > &a, int& x)
	{
		int res=0,cur;
		for(int i = 0; i < (int)a.size(); i++){
		if ((cur=move(a[i].first, a[i].second, x))==-INF1)
			return -INF1;
		res+=cur;
				
		}
		return res;
	}

};

const int D=3;
int t[D],res,tRes[D],h,cH;
deque<int> q;
int qe;

void go(field a,int num,int x,int cRes){
//	cerr<<num<<endl;
	if(num==D){
		cH=a.getH();

		if(cRes*100-cH > res*100-h) {
			res=cRes;
			h=cH;
			memcpy(tRes,t,sizeof(t));
		}
		return;
	}
	int i,r,e;
	field b;
	for(i=1;i<=W;i++)
		for(r=0;r<4;r++){
			b=a;
			int xx=x;
			e=b.move(i,r,xx);
			t[num]=(i<<2)+r;
			go(b,num+1,next(x),cRes+e);
		}
}
char s[H+2][W+2];
char eS[H+2][W+2];
int x;

void kill(){
	field a(s);

/*	if(!q.empty()){
		vector< pair<int,int> > g;
		for(int i=0;i<(int)q.size();i++)
			g.pb((make_pair((tRes[i]>>2),(tRes[i]&3))));
		int xx=x;
		field b=a;
		if(b.moveAll(g,xx)+qe==res){

			tRes[0]=q[0];
			q.pop_front();
			printf("%d %d\n",(tRes[0]>>2)-1-((tRes[0]&3)==2),(tRes[0]&3));
			xx=x;
			qe+=a.move((tRes[0]>>2),(tRes[0]&3),xx);
			return;
		}
	}
*/	
	res=-INF1;
	tRes[0]=4;
	h=H+1;

//	cerr<<a.getH()<<endl;
	go(a,0,x,0);
	for(int i=1;i<D;i++)
		q.pb(tRes[i]);
//	cerr<<h<<endl;
	qe=0;
	printf("%d %d\n",(tRes[0]>>2)-1-((tRes[0]&3)==2),(tRes[0]&3));
	int xx=x;
	qe+=a.move((tRes[0]>>2),(tRes[0]&3),xx);
	fflush(stdout);

}

int main() {
	for (int i = 8; i <= H*W; i++)
		bonus[i] = bonus[i-1];
	int x0;
	freopen("log.txt","w",stderr);
	q.clear();

	for(int i = 0 ; ; ++i) {
		//cerr<<i<<endl;
		char str[100];
		scanf("%s",str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			scanf("%d", &x0);
			x=x0;
			printf("Kleban\n");

			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {

			memset(s,0,sizeof(s));

			//our field
			for(int j = 1; j <= H; j++)
				scanf("%s",s[j]+1);

			memset(eS,0,sizeof(eS));
			for(int j = 1; j <= H; j++)
				scanf("%s",eS[j]+1);
			x=next(x);

			kill();

			fflush(stdout);
		}
	}

	return 0;
}
