#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int w = 8, h = 16, inf = 2147483640;
const int xgo[4] = {1, 0, -1, 0};
const int ygo[4] = {0, -1, 0, 1};
const int movebonus[7] = {0, 0, 3, 6, 12, 24, 50};
const int areaval[3] = {-2, 1, 6};

int my[h + 2][w + 2], his[h + 2][w + 2];
int mycur[h + 2][w + 2], hiscur[h + 2][w + 2];
int x[1000], y[1000];
bool f[h + 2][w + 2];
int grand;
int vspglob;

void out(int x) {
}

void out(char * x) {
}

int myrand() {
	return grand = (grand * 17236517 + 4311271) % 87465851;
}

int type (char c) {
	if (c == '*')
		return -1; // black stone
	else if (c == '.')
		return 0; // null
	else
		return c - '0';
}

int delx[1000], dely[1000], del;

int bfs(int xs, int ys, int col){
	x[0] = xs;y[0] = ys;
	delx[0] = xs; dely[0] = ys;
	del = 0;
	int cur = 0, sh = 1;
	int xto, yto, i;
	while (cur < sh){
		for (i = 0;i < 4;i++){
			xto = x[cur] + xgo[i];yto = y[cur] + ygo[i];
			if ((xto > -1) && (xto < h) && (yto > -1) && (yto < w)){
				if ((!f[xto][yto]) && (my[xto][yto] == col)){
					f[xto][yto] = true;
					x[sh] = xto;y[sh] = yto;
					sh++;
					delx[del] = xto; dely[del] = yto;
					del ++;
				}
				if (!f[xto][yto] && my[xto][yto] == -1) {
					delx[del] = xto; dely[del] = yto;
					del ++;
				}
			}
		}
		cur++;
	}
	vspglob = sh;
	return sh;
}

bool oblastexist(){
	int i, j;
	for (i = 0;i < h;i++)
		for (j = 0;j < w;j++)
			f[i][j] = false;
	for (i = 0;i < h;i++)
		for (j = 0;j < w;j++)
			if ((!f[i][j]) && (my[i][j] > 0))
				if (bfs(i, j, my[i][j]) > 3)
					return true;
	return false;
}

bool inair(){
	for (int i = 1;i < h;i++){
		for (int j = 0;j < w;j++){
			if ((my[i][j] != 0) && (my[i - 1][j] == 0)){
				return true;
			}
		}
	}
	return false;
}

int findanddelete(){
//	out("find");
	int i, j, res = 0;
	// find
	for (i = 0;i < h;i++)
		for (j = 0;j < w;j++)
			f[i][j] = false;
	int xcur = -1, ycur = -1;
	for (i = 0;i < h;i++){
		for (j = 0;j < w;j++){
			if ((!f[i][j]) && (my[i][j] > 0)){
				if ((res = bfs(i, j, my[i][j])) > 3){
					xcur = i;ycur = j;
					break;
				}
			}
		}
		if (xcur + 1){
			break;
		}
	}

	if (res < 4)
		return 0;

	for (i = 0;i < del;i++){
		my[delx[i]][dely[i]] = 0;
	}

//	out("out of find");
//	out(res);
	return res;
}

int domove(){
	int res = 0, t, areas = 0;
	while (t = findanddelete()){
		areas ++;
		res += t;
	}

	for (int i = 0; i < w; i ++) {
		int last = 0;
		for (int j = 0; j < h; j ++)
			if (my[j][i] != 0) {
				my[last][i] = my[j][i];
				my[j][i] = 0;
				last ++;	
			}
	}

	return res - areas - 2;
}

int bonusmove(int k) {
	if (k > 6)
		return 100;

	return movebonus[k];
}

int model(pair <int, int> move, int pos, int whoisleft, int left){
	int fir, sec, i, j, vsp;
	// copying data
	for (i = 0;i < h;i++){
		for (j = 0;j < w;j++){
			mycur[i][j] = my[i][j];
		}
	}
	// checking that we can put balls
	if (whoisleft){
		vsp = move.first;move.first = move.second;move.second = vsp;
	}
	for (fir = 0;(my[fir][left]) && (fir < h);fir++){
	}
	if (pos == 0){
		if (fir == h - 1)
			return -inf;
		sec = fir + 1;
	}else
	{
		for (sec = 0;(my[sec][left + 1]) && (sec < h);sec++){
		}
	}
//	out("zero");

	if ((fir == h) || (sec == h)){
		return -inf;
	}
	// putting balls
	my[fir][left] = move.first;
	if (pos == 0){
		my[sec][left] = move.second;
	}else
	{
		my[sec][left + 1] = move.second;
	}
	// and... the game is running ;-)
//	out("first step...");
	int cmove = 0, bonus = 0;
	while (oblastexist() || inair()){
//		out("domove");
		bonus += domove();
//		out("out of domove");
		cmove ++;
	}                  

//	out("second step");

	bonus += bonusmove(cmove);

	int res = 0;
	for (int i =0; i < h; i ++)
		for (int j = 0; j < w; j ++)
			f[i][j] = 0;
	for (int i = 0; i < h; i ++) {
		for (int j = 0; j < w; j ++)
			if (!f[i][j] && my[i][j] > 0)
				res += areaval[bfs(i, j, my[i][j]) - 1];
	}

	// returning data
	for (i = 0;i < h;i++){
		for (j = 0;j < w;j++){
			my[i][j] = mycur[i][j];
		}
	}

	return 2 * bonus + res;
}

bool isdebut() {
	return 0;
}

char str[100];

int main()
{
  while (1)
	{
		scanf("%s",str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			scanf("%d", &grand);
			printf("UATSON\n"); //???
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {

			for(int j = 0; j < h; j++) {
				scanf("%s", str);
				for (int i = 0; i < w; i ++)
					my[h - j - 1][i] = type(str[i]);
			}
			for(int j = 0; j < h; j++) {
				scanf("%s", str);
				for (int i = 0; i < w; i ++)
					his[h - j - 1][i] = type(str[i]);
			}

			pair <int, int> move = make_pair(myrand() % 5 + 1, myrand() % 5 + 1);

			int max, posbest, whoisleftbest, ibest;
			int to, vsp;

			if (isdebut()){
			}else
			{
				max = -inf;
				posbest = 0;
				whoisleftbest = 0;
				ibest = 0;
				for (int pos = 0;pos < 2;pos++){// 0 if vertical, 1 is horizontal
					for (int whoisleft = 0;whoisleft < 2;whoisleft++){
						to = 8;
						if (pos)
							to--;
						for (int i = 0;i < to;i++){
							//out("model");
							vsp = model(move, pos, whoisleft, i);
							out(vsp);
							if (vsp > max/* || (vsp == max && (grand & 1))*/){
								max = vsp;
								posbest = pos;
								whoisleftbest = whoisleft;
								ibest = i;
								out("!!!");
							}
							//out("out of model");
						}
					}
				}
			}

			out(max);

			int fir, sec;

			if (whoisleftbest == 0){
				fir = ibest;
				if (posbest == 0){
					sec = 3;
				}else
				{
					sec = 0;
				}
			}else
			{
				sec = ibest;
				if (posbest == 0){
					fir = sec;
					sec = 1;
				}else
				{
					fir = sec;
					sec = 2;
				}
			}

			out(whoisleftbest);
			out(posbest);
			out(ibest);
			out("\n");
			out(fir);
			out(sec);
			out("===========================\n");

			printf("%d %d\n",fir,sec);

			//print here current move

			//printf("%d %d\n", 0, 0);
			fflush(stdout);
		} 
		else return 0;
	}

	return 0;
}
