#define _CRT_SECURE_NO_DEPRECATE

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define fi(a,b) for (i=a;i<=b;i++)
#define fj(a,b) for (j=a;j<=b;j++)
#define fo(a,b) for (o=a;o<=b;o++)
#define fdi(a,b) for (i=a;i>=b;i--)
#define fdj(a,b) for (j=a;j>=b;j--)
#define fdo(a,b) for (o=a;o>=b;o--)

#define COPY(a,b) memcpy(a,b,sizeof(b))
#define ZERO(a) memset(a,0,sizeof(a))

#define INF 1000000000

typedef char field[17][9];

#undef PRINT

long long x;

int n = 8, m = 16;

field matr;

#ifdef PRINT
FILE *f;
#endif

void Read() {
	int j;
	fj(1, m) {
		scanf("%s", matr[j] + 1);
	}
}

int pos, rot;

void Down(int x, int c) {
	int y;
	y = 0;
	while (y < m && matr[y + 1][x] == '.') y++;
	matr[y][x] = c + '0';
}

bool Down2(int p, int r, int color1, int color2) {
	if (r == 0) {
		if (p == 8) return false;
		if (matr[1][p] != '.') return false;
		if (matr[1][p + 1] != '.') return false;		
		Down(p, color1);
		Down(p + 1, color2);
	} else if (r == 1) {
		if (matr[2][p] != '.') return false;
		Down(p, color2);
		Down(p, color1);
	} else if (r == 2) {
		if (p == 1) return false;
		if (matr[1][p] != '.') return false;
		if (matr[1][p - 1] != '.') return false;
		Down(p, color1);
		Down(p - 1, color2);
	} else if (r == 3) {
		if (matr[2][p] != '.') return false;
		Down(p, color1);
		Down(p, color2);
	}
	return true;
}

int color[17][9];
int C;
int C0;

queue <pair<int, int> > qu;

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

bool Field(int x, int y) {
	if (x < 1 || x > n) return false;
	if (y < 1 || y > m) return false;
	return true;
}

bool b[10000000];

int bflag;

int br;

void bfs(int x, int y) {
	int i;
	int c;
	int q;
	pair <int, int> t, t2;
	q = 0;
	c = matr[y][x];
	qu.push(mp(x, y));
	C++;
	color[y][x] = C;
	while (!qu.empty()) {
		t = qu.front();
		qu.pop();
		q++;
		fi(0, 3) {
			t2.first = t.first + dx[i];
			t2.second = t.second + dy[i];
			if (!Field(t2.first, t2.second)) continue;
			if (matr[t2.second][t2.first] != c) continue;			
			if (color[t2.second][t2.first] == C) continue;
			color[t2.second][t2.first] = C;
			qu.push(t2);
		}
	}
	if (q >= 4) {
		br++;
		b[C] = 1;
		bflag = true;
	}
}

int Burn() {
	int i, j, o;
	int d;
	int x2, y2;
	int q;
	int Q;
	int p;
	p = 0;
	Q = 0;
	while (1) {
		bflag = false;
		C0 = C;
		br = 0;
		fj(1, m) {
			fi(1, n) {
				if (matr[j][i] >= '1' && matr[j][i] <= '5' && color[j][i] <= C0) {
					bfs(i, j);
				}
			}
		}
		if (!bflag) break;

		p++;

		q = 0;

		fj(1, m) {
			fi(1, n) {
				if (b[color[j][i]]) {
					q++;
					matr[j][i] = '.';
					color[j][i] = 0;
					fo(0, 3) {
						x2 = i + dx[o];
						y2 = j + dy[o];
						if (!Field(x2, y2)) continue;
						if (matr[y2][x2] == '*') {
							matr[y2][x2] = '.';
						}
					}
				}
			}
		}

		Q += q - br - 2;

		fi(1, n) {
			d = 0;
			fdj(m, 1) {
				if (matr[j][i] == '.') {
					d++;
				} else if (d != 0) {
					matr[j + d][i] = matr[j][i];
					matr[j][i] = '.';
				}
			}
		}

		
	}

	if (p == 1) Q += 0;
	if (p == 2) Q += 3;
	if (p == 3) Q += 6;
	if (p == 4) Q += 12;
	if (p == 5) Q += 24;
	if (p == 6) Q += 50;
	if (p >= 7) Q += 100;

	return Q;
}

int sqr(int x) {
	return x * x;
}

int Pow(int x, int y) {
	int i;
	int res;
	res = 1;
	fi(1, y) {
		res *= x;
	}
	return res;
}

int Score() {
	int i, j;
	int res;
	int bl;
	res = 0;
	bl = 0;
	fj(1, m) {
		fi(1, n) {
			if (matr[j][i] != '.') res += Pow(m - j + 1, 2);
			if (matr[j][i] == '*') bl++;
		}
	}

	res += 3 * bl;

	return res;
}

void Print() {
#ifdef PRINT
	int i, j;
	fj(1, m) {
		fi(1, n) {
			fprintf(f, "%c", matr[j][i]);
		}
		fprintf(f, "\n");
	}
	fprintf(f, "\n");
	fflush(f);
#endif
}

int DEPTH = 3;

int Fun(int depth, long long x) {
	int i, j;
	int color1, color2;
	if (depth == DEPTH) {
		return Score();
	}
	int v;
	int res;
	int bv;
	res = INF;
	field t;
	COPY(t, matr);

	color1 = x % 5 + 1;

	x = (x * 17235617LL + 4311271LL) % 87465851LL;

	color2 = x % 5 + 1;

	x = (x * 17235617LL + 4311271LL) % 87465851LL;

	fi(1, 8) {
		fj(0, 3) {
			COPY(matr, t);
			if (Down2(i, j, color1, color2)) {
				bv = Burn();

				//Print();

				v = Fun(depth + 1, x);

				if (v != INF) v -= 2 * bv;

				if (v < res) {
					res = v;
					if (depth == 0) {
						pos = i;
						rot = j;
					}
				}

			}
		}
	}

	if (res == INF) return Score();

	return res;
}

void Move(int qhod) {
	//field t;

	pos = 1;
	rot = 1;

	//COPY(t, matr);
		
	ZERO(color);
	C = 0;

	Fun(0, x);
	
	//COPY(matr, t);

	//Down2(pos, rot, color1, color2);

	//Print();

	if (rot == 2) {
#ifdef PRINT
	fprintf(f, "Move %d %d\n", pos - 2, rot);
	fflush(f);
#endif
		printf("%d %d\n", pos - 2, rot);
	} else {
#ifdef PRINT
	fprintf(f, "Move %d %d\n", pos - 1, rot);
	fflush(f);
#endif
		printf("%d %d\n", pos - 1, rot);
	}
}

void Check() {
	int i, j;
	int q;
	q = 0;
	fj(1, m) {
		fi(1, n) {
			if (matr[j][i] != '.') q++;
		}
	}
	if ((q * 100) / (n*m) >= 60) {
		DEPTH = 2;
	} else {
		DEPTH = 3;
	}
}

int main() {

#ifdef PRINT
	f = fopen("log2.txt", "w");
#endif

	memset(color, 0, sizeof(color));

	for(int i = 0 ; ; i++) {
		char str[100];
		scanf("%s",str);	
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			scanf("%lld", &x);
			printf("IzhSTU\n");
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {
			/*

			x = (x * 17235617 + 4311271) % 87465851;

			color1 = x % 5 + 1;

			x = (x * 17235617 + 4311271) % 87465851;

			color2 = x % 5 + 1;

			*/

			Read();

			Check();

#ifdef PRINT
			Print();
			fprintf(f, "%lld\n", x);
#endif

			Move(i);

#ifdef PRINT
			fprintf(f, "%lld\n", x % 5 + 1);
#endif
			x = (x * 17235617LL + 4311271LL) % 87465851LL;

#ifdef PRINT
			fprintf(f, "%lld\n", x % 5 + 1);
#endif

			x = (x * 17235617LL + 4311271LL) % 87465851LL;
			fflush(stdout);
		}
	}

	return 0;
}
