#pragma comment (linker, "/STACK:32000000")
#define _MATH_DEFINES_DEFINED
#define _CRT_SECURE_NO_WARNINGS

#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <string>
#include <list>
#include <cstdlib>
#include <ctime>

#ifdef ONLINE_JUDGE
# define dbg if(1) {} else cerr
#else
#include <fstream>
std::ofstream fout("log.txt");
# define dbg fout
#endif

using namespace std;

#define fi(n) for (int i = 0; i < (n); ++i)
#define fj(n) for (int j = 0; j < (n); ++j)
#define fk(n) for (int k = 0; k < (n); ++k)
#define fr(i, f, t) for (int i = (f); i < (t); ++i)
#define mp make_pair
#define pb push_back
#define CLR(a, v) memset((a), (v), sizeof(a))
#define clr(a) CLR(a, 0);
#define all(a) (a).begin(), (a).end()

typedef unsigned uint;
typedef unsigned char uchar;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf = 1 << 30;
const ll infl = 1ll << 60;
const double eps = 1e-8;

char str[100];
enum { w = 8, h = 16 };
enum { Right = 0, Down = 1, Left = 2, Up = 3 };
int x;
char ofield[h][w + 1];
char efield[h][w + 1];
char tfield[h][w + 1];
enum { ColNum = 100000 };
pii cols[ColNum];
int curstep;
char u[h][w];
int heights[w];
int colorsbyh[w];

int nextx()
{
	x = (x * 17235617ll + 4311271ll) % 87465851;
	return x;
}

pii make_colors()
{
	int cx = x % 5;
	int cy = nextx() % 5;
	pii ans = mp(cx, cy);
	ans.first += '1';
	ans.second += '1';
	nextx();
	return ans;
}

pii colors(int step)
{
	return cols[(step + curstep) % ColNum];
}

void fill_colors()
{
	fi (ColNum)
		cols[i] = make_colors();
	fi (20)
		dbg << char(cols[i].first) << " " << char(cols[i].second) << endl;
	dbg << endl;
}

void set_name(const char *name)
{
	printf("%s\n", name);
}

void make_move(int x, int r)
{
	if (x == w - 1 && (r == Right || r == Left))
		r = 1;
	dbg << x << " " << r << endl;
	printf("%d %d\n", x, r);
	curstep++;
	//cols[curstep++] = make_colors();
}

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

bool is_invalid(int x, int y)
{
	return (x < 0 || x >= h || y < 0 || y >= w);
}

pii dead[w * h];
int deadn;

int dfs(int x, int y)
{
	if (tfield[x][y] == '.')
		return 0;
	int sum = 1;
	dead[deadn++] = mp(x, y);
	u[x][y] = 1;
	fi (4) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (is_invalid(nx, ny))
			continue;
		if (tfield[x][y] != tfield[nx][ny] || u[nx][ny])
			continue;
		sum += dfs(nx, ny);
	}
	return sum;
}

void killthem()
{
	dbg << "before " << deadn << endl;
	fi (h)
		dbg << tfield[i] << endl;
	fi (deadn) {
		int x = dead[i].first;
		int y = dead[i].second;
		dbg << "(" << x << ", " << y << "), ";
		tfield[x][y] = '.';
		while (x > 0 && tfield[x - 1][y] != '.') {
//			u[x][y] = 1;
			swap(tfield[x - 1][y], tfield[x][y]);
			--x;
		}
	}
	dbg << endl << "after" << endl;
	fi (h)
		dbg << tfield[i] << endl;
	dbg << endl;
}

int bonuses[] = {
	0, 0, 3, 6, 12, 24, 50, 100,
	100, 100, 100, 100, 100, 100, 100, 100,
	100, 100, 100, 100, 100, 100, 100, 100,
	100, 100, 100, 100, 100, 100, 100, 100,
	100, 100, 100, 100, 100, 100, 100, 100,
	100, 100, 100, 100, 100, 100, 100, 100,
	100, 100, 100, 100, 100, 100, 100, 100 
};

int sn;

pii dfscol(int x1, int y1, int x2, int y2)
{
	deadn = 0;
	sn = 0;
	clr(u);
	int res = 0;
	int b = 0;
	int s = 0;
	int maxres = 0;
	/*if (heights[x] != h) {
		tfield[x][heights[x]] = c;
		res = dfs(x, heights[x]) + 1;
		if (res > 4) {
			sn = 1;*/
			int len = 0;
			do {
				++len;
				s += max(deadn - sn - 2, 0);
				killthem();
				deadn = 0;
				sn = 0;
				clr(u);
				if (len == 1) {
					res = dfs(x1, y1);
					maxres = max(maxres, res);
					if (res < 4) {
						deadn -= res;
					} else {
						sn++;
					}
					res = u[x2][y2] ? 0 : dfs(x2, y2);
					maxres = max(maxres, res);
					if (res < 4) {
						deadn -= res;
					} else {
						sn++;
					}
				}
				fi (h) fj (w) {
					res = (u[i][j] || tfield[i][j] == '.') ? 0 : dfs(i, j);
				//	maxres = maxres + (res > 1 ? res : 0); //max(res, maxres);
				//	maxres = max(res, maxres);
					if (res < 4) {
						deadn -= res;
					} else {
			//			dbg << "!!!" << i << " " << j << " " << tfield[i][j] << " " << res << endl;
						sn++;
					}
				}
				if (sn == 0)
					--len;
	//			dbg << s << " " << " " << sn << " " << deadn << endl;
			} while (sn > 0);
			s += bonuses[len];
//		}
//		return b;
//	}
			dbg << "------------" << s << " " << maxres << endl;
	return mp(s, maxres);
}

template <typename T>
pii scorebymap(int x, int r, const T &field)
{
	if (x == w - 1 && (r == Right || r == Left))
		return mp(-inf, -inf);
	fi (h)
		memcpy(tfield[i], field[i], sizeof(tfield[i]));
//	memcmp(tfield, field, sizeof(tfield));
	pii c = colors(0);
	pii a1, a2;
	switch (r) {
	case Right:
		a1 = mp(heights[x] - 1, x);//         = c.first;
		a2 = mp(heights[x + 1] - 1, x + 1);// = c.second;
		break;
	case Left:
		a1 = mp(heights[x + 1] - 1, x + 1);//] = c.first;
		a2 = mp(heights[x] - 1, x);//]         = c.second;
		break;
	case Up:
		a1 = mp(heights[x] - 1, x);//]     = c.first;
		a2 = mp(heights[x] - 2, x);//] = c.second;
		break;
	case Down:
		a1 = mp(heights[x] - 2, x);//] = c.first;
		a2 = mp(heights[x] - 1, x);//]     = c.second;
		break;
	default:
		*((int*)0) = 0;
		dbg << "Neveroyatno!!!" << endl;
		exit(1);
		break;
	}
	if (is_invalid(a1.first, a1.second) || is_invalid(a2.first, a2.second))
		return mp(-inf, -inf);
	tfield[a1.first][a1.second] = c.first;
	tfield[a2.first][a2.second] = c.second;
	return dfscol(a1.first, a1.second, a2.first, a2.second);
}

pair<pii, pii> variants[w * 4];
int vn;
pii vs;

bool varLessThen(const pair<pii, pii> &a, const pair<pii, pii> &b)
{
	return a.first > b.first || (a.first == b.first && heights[a.second.first] > heights[b.second.first]);
	//return heights[a.first] > heights[b.first] || (heights[a.first] == heights[b.first] && (rand() & 1));
}

void make_move()
{
	fi (h) {
		scanf("%s", &ofield[i][0]);
		dbg << "> " << ofield[i] << endl;
	}
	fi (w) {
		fj (h) {
			heights[i] = h;
			if (ofield[j][i] != '.') {
				heights[i] = j;
				colorsbyh[i] = ofield[j][i];
				break;
			}
		}
	}
	fi (h)
		scanf("%s", &efield[h][0]);
	vn = 0;
	vs = mp(0, 0);
	pii res;
	fi (w) fj (4) {
		res = scorebymap(i, j, ofield);
		if (res.first > vs.first)
			vn = 0;
		if (res.first >= vs.first) {
			variants[vn++] = mp(res, mp(i, j));
			vs = res;
		}
	}
	sort(variants, variants + vn, varLessThen);
	dbg << "!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
	fi (vn) {
		dbg << variants[i].first.first << " " << variants[i].first.second
			<< " "
			<< variants[i].second.first << " " << variants[i].second.second
			<< endl;
	}
	dbg << endl << "-- " << char(colors(0).first) << " " << char(colors(0).second) << " " << curstep << endl;
	pair<pii, pii> turn = variants[0];
	make_move(turn.second.first, turn.second.second);
	//pii c = colors(0);
	//make_move(rand() % w, rand() % 4);
}

int main()
{
	// RANDOM!!!
	curstep = 0;
	srand(int(time(0)) ^ reinterpret_cast<int>(&x));
	for(int i = 0 ; ; ++i) {
		scanf("%s", str);
		if(!strcmp(str, "Quit"))
		  break;
		if(!strcmp(str, "Start")) {
			scanf("%d", &x);
			fill_colors();
			set_name("BrainlessThing");
		} else if(!strcmp(str, "Move")) {
			make_move();
		}
		fflush(stdout);
	}

	return 0;
}
