#include <cstdio>
#include <cstring>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;


const int w = 8, h = 16;
int x0;
const int maxQ = 1000;
char player[2][h + 2][w + 2];
char board[h + 2][w + 2];
bool use[h + 2][w + 2];
int X1, X2;
const int infty = 1e9;
int sx[] = {-1, 0, 0, 1};
int sy[] = { 0,-1, 1, 0};
int TMP;


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


struct Move{
	
	pair<char, char> color;

	int pos, state;
		
};


int len;
pair<int, int> q[maxQ];


//int getMarkFunction(int gr1, int gr2, int neq, int h1, int h2, int b1, int b2, int p)
//{
//	return p * 100046 + (16 - h1) * (16 - h2) * 146 + (b1 * gr1 + neq * b2 * gr2) * 14 + 6;
//}


void add(pair<int, int> _, int c)
{
	if(use[ _.first ][ _.second ])
	{
		return;
	}
	int myC = board[_.first][_.second];
	if( myC == c || myC == '*')
	{
		use[ _.first ][ _.second ] = true;
		q[len++] = _;
	}
}


bool isIn(int x1, int x, int x2)
{
	return x1 <= x && x <= x2;
}


bool good(pair<int, int> _)
{
	return isIn(0, _.first, h - 1) && isIn(0, _.second, w - 1);
}



void refresh()
{
	for(int j = 0; j < w; j++)
	{
		int cur = 0;
		for(int i = 0; i < h; i++)
		{
			if(board[i][j] != '.')
			{
				board[cur++][j] = board[i][j];
			}
		}
		for(int i = cur; i < h; i++)
		{
			board[i][j] = '.';
		}
	}
}


pair<int, int> bfs(int i, int j)
{
	pair<int, int> _ = make_pair(i, j);
	int c0 = board[i][j];
	if(c0 == '*' || c0 == '.')
	{
		return make_pair(0, 0);
	}
	len = 0;
	add(_, c0);
	int black = 0;
	for(int i = 0; i < len; i++)
	{
		_ = q[i];
		int c = board[ _.first ][ _.second ];
		if(c == '*')
		{
			black++;
			continue;
		}
		for(int t = 0; t < 4; t++)
		{
			pair<int, int> cur = _;
			cur.first += sx[t];
			cur.second += sy[t];
			if(!good(cur) )
			{
				continue;
			}
			add(cur, c0);
		}
	}
	if(len - black >= 4)
	{
		for(int i = 0; i < len; i++)
		{
			board[ q[i].first ][ q[i].second ] = '.';
		}
	}
	return make_pair(len - black, black);
}


pair<int, int> startLavina(bool & inv)
{
	int blacks = 0;
	int score = 0;
	int res = 0;
	memset(use, false, sizeof use);
	inv = false;
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			if(board[i][j] == '.' || board[i][j] == '*') continue;
			pair<int, int> count = bfs(i, j);
			if(count.first > 0)
			{
				res++;
			}
			blacks += count.second;
			if(count.first >= 4)
			{
				inv = true;
				score += count.first - 3;
			}
		}
	}
	return make_pair(res, blacks);
}


void swapPair(pair<char, char> & p)
{
	swap(p.first, p.second);
}


bool pushMove(int pos, int c, int & resH)
{
	int cur = h - 1;
	if(board[cur][pos] != '.')
	{
		resH = h;
		return false;
	}
	while(cur > 0 && board[cur][pos] == '.')
	{
		cur--;
	}
	board[cur][pos] = c;
	resH = cur;
	return true;
}


bool pushMove(int pos, pair<int, int> c, int & h)
{
	bool res = true;
	int h1, h2;
	res &= pushMove(pos, c.second, h1);
	res &= pushMove(pos, c.first, h2);
	h = h2;
	return res;
}


bool startMove(Move move, int & h1, int & h2)
{
	bool inv = false;
	if(move.state == 3)
	{
		swapPair(move.color);
		move.state = 1;
		inv = true;
	}
	if(move.state == 2)
	{
		swapPair(move.color);
		move.state = 0;
		move.pos--;
		inv = true;
	}
	bool res;
	if(move.state == 0)
	{
		if(move.pos == -1 || move.pos == w - 1)
		{
			return false;
		}
		res = pushMove(move.pos, move.color.first, h1) &&
		pushMove(move.pos + 1, move.color.second, h2);
	}
	if(move.state == 1)
	{
		int h;
		res = pushMove(move.pos, move.color, h);
		h1 = h - 1;
		h2 = h;
	}
	if(inv)
	{
		swap(h1, h2);
	}
	return res;
}


int getVaginaPoints(int n)
{
	const int p[] = {0, 0, 3, 6, 12, 24, 50, 100};
	if(n > 7)
		n = 7;
	return p[n];
}


int getPoint(vector<Move> moves, int & h)
{
	int h1, h2;
	int res = 0;
	int answer = 0;
	memcpy(board, player[0], sizeof board);
	int resH = 0;
	for(int i = 0; i < moves.size(); i++)
	{
		if(!startMove(moves[i], h1, h2) )
		{
			return 1e9;
		}
		resH = max(h1, resH);
		resH = max(h2, resH);
		int curPoint = 0;
		int vaginaCnt = 0;
		bool inv = false;
		while(true)
		{
			pair<int, int> add = startLavina(inv);
			answer = add.first;
			break;
			if(!inv)
			{
				break;
			}
			inv = true;
			answer += add.first;
			break;
			refresh();
			curPoint += add.first;
			vaginaCnt++;
		}
		res += curPoint + getVaginaPoints(vaginaCnt);
	}
	h = resH;
	return answer;
}


int getColor(int x)
{
	return '0' + x % 5 + 1;
}


pair<int, int> getBestMove()
{
	int X3 = nxt(X2);
	int X4 = nxt(X3);
	int X5 = nxt(X4);
	int X6 = nxt(X5);
	char c1 = getColor(X1);
	char c2 = getColor(X2);
	char c3 = getColor(X3);
	char c4 = getColor(X4);
	char c5 = getColor(X5);
	char c6 = getColor(X6);
//	return make_pair(rand() % 4, rand() % 4);
	int bestPoint = 1e9;
	int I, J, H = 100;
	int I2, J2, H2 = 100;
	int bestPoint2 = 1e9;
	for(int i1 = 0; i1 < 8; i1++) for(int j1 = 0; j1 < 4; j1++)
	{
		Move move1 = {make_pair(c1, c2), i1, j1};
//		for(int i2 = 0; i2 < 8; i2++) for(int j2 = 0; j2 < 4; j2++)
		{
//			Move move2 = {make_pair(c3, c4), i2, j2};
			//for(int i3 = 0; i3 < 8; i3++) for(int j3 = 0; j3 < 4; j3++)
			{
				//Move move3 = {make_pair(c5, c6), i2, j2};
				vector<Move> mv;
				mv.clear();
				mv.push_back(move1);
//				mv.push_back(move2);
				//mv.push_back(move3);
				int h;
				int point = getPoint(mv, h);
				if(point < bestPoint || (point == bestPoint && h < H) )
				{
					bestPoint = point;
					I = i1;
					J = j1;
					H = h;
				}
				if(h < 10)
				{
					if(point < bestPoint2 || (point == bestPoint2 && h < H2) )
					{
						bestPoint2 = point;
						I2 = i1;
						J2 = j1;
						H2 = h;
					}
				}
			}
		}		
	}
	if(bestPoint2 < 1e9)
	{
		return make_pair(I2, J2);
	}
	return make_pair(I, J);
}



int main()
{
//	freopen("input.txt", "r", stdin);
	for(int i = 0; true; i++)
	{
		char str[100];
		scanf("%s",str);
		if(strcmp(str,"Quit") == 0)
		{
			break;
		}
		if(strcmp(str,"Start") == 0)
		{
			scanf("%d", &x0);
			X1 = x0;
			printf("UncleAlexus\n");
			fflush(stdout);
			continue;
		}
		if(strcmp(str,"Move") == 0)
		{
			for(int team = 0; team < 2; team++)
			{
				for(int j = h - 1; j >= 0; j--)
				{
					scanf("%s", player[team][j]);
				}
			}
			X2 = nxt(X1);
			pair<int, int> _ = getBestMove();
			printf("%d %d\n", _.first, _.second);
			fflush(stdout);
			X1 = nxt(X2);
		}
	}
	return 0;
}
