#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

#define W 8
#define H 16
#define BLACK 10
#define NIL 0
int x0;
int field[W+2][H+2], sandbox[W+2][H+2], col1, col2;
bool used[W+2][H+2];
bool used_glob[W+2][H+2];
char input[H][W];


void copyfield()
{
	memcpy(sandbox, field, sizeof(field));
}

int bfs(pair<int, int> pt)
{
	queue< pair<int, int> > q;
	q.push(pt);
	memset(used, 0, sizeof(used));
	used[pt.first][pt.second] = true;
	int k = 0;
	while (!q.empty())
	{
		k++;
		pair<int, int> p = q.back();
		q.pop();
		int color = sandbox[p.first][p.second];
		//coloured
		if (color == sandbox[p.first+1][p.second] && !used[p.first+1][p.second])
		{
			q.push(make_pair(p.first+1, p.second));
			used[p.first+1][p.second] = true;
		}

		if (color == sandbox[p.first-1][p.second] && !used[p.first-1][p.second])
		{
			q.push(make_pair(p.first-1, p.second));
			used[p.first-1][p.second] = true;
		}

		if (color == sandbox[p.first][p.second+1] && !used[p.first][p.second+1])
		{
			q.push(make_pair(p.first, p.second+1));
			used[p.first][p.second+1] = true;
		}

		if (color == sandbox[p.first][p.second-1] && !used[p.first][p.second-1])
		{
			q.push(make_pair(p.first, p.second-1));
			used[p.first][p.second-1] = true;
		}
		//black
		if (BLACK == sandbox[p.first+1][p.second] && !used[p.first+1][p.second])
		{
			used[p.first+1][p.second] = true;
		}

		if (BLACK == sandbox[p.first-1][p.second] && !used[p.first-1][p.second])
		{
			used[p.first-1][p.second] = true;
		}

		if (BLACK == sandbox[p.first][p.second+1] && !used[p.first][p.second+1])
		{
			used[p.first][p.second+1] = true;
		}

		if (BLACK == sandbox[p.first][p.second-1] && !used[p.first][p.second-1])
		{
			used[p.first][p.second-1] = true;
		}
	}
	if(k > 3)
	{
		//explode
		for (int i=1;i<=W;i++)
		{
			for (int j=1;j<=H;j++)
			{
				if (used[i][j])
				{
					sandbox[i][j] = NIL;
				}

			}
		}
		return k;
	}
	return 0;
}

void drop(int pos, int color)
{
	for (int i=1;i<=H;i++)
	{
		if (sandbox[pos][i] == 0)
		{
			sandbox[pos][i] = color;
			break;
		}
	}
}

bool HasValues(int i, int jj)
{
	for (int j = jj; j <= H; j++)
	{
		if (sandbox[i][j] != 0)
			return 1;
	}
	return 0;
}

void lavina()
{
	for(int i = 1; i <= W; i++)
	{
		for (int j = 1; j <= H; j++)
		{
			if (sandbox[i][j] == NIL && HasValues(i, j))
			{
				for (int k = j+1; k <= H; k++)
				{
					sandbox[i][k-1] = sandbox[i][k];	
				}
				j--;
				
			}
		}
	}

}

int explode()
{
	memset(used_glob, 0, sizeof(used_glob));
	int ballCount = 0;
	int areas = 0;
	int points = 0;
	for (int i=1;i<=W;i++)
	{
		for (int j=1;j<=H;j++)
		{
			if (sandbox[i][j] != NIL && !used_glob[i][j])
			{
				used_glob[i][j] = true;
				int curBalls = bfs(make_pair(i, j));
				if (curBalls > 0)
				{
					points += curBalls;
					areas++;
				}

			}
		}
	}
	if(points == 0)
		return 0;
	return points - areas - 2;
}

int calcField(int pos, int dir)
{
	copyfield();
	switch (dir)
	{
		case 0: drop(pos, col1);
				drop(pos+1, col2);
				break;
		case 1: drop(pos, col2);
				drop(pos, col1);
				break;
		case 2: drop(pos, col1);
				drop(pos-1, col2);
				break;
		case 3: drop(pos, col1);
				drop(pos, col2);
				break;
	}
	int total = 0;
	int lav = 0;
	int sum = 0;
	while (1)
	{
		int p = explode();
		if(p > 0)
		{
			lav++;
			sum += p;
			lavina();
		}
		else
			break;
	}
	switch(lav)
	{
	case 2:
		total += 3;
		break;
	case 3:
		total += 6;
		break;
	case 4:
		total += 12;
		break;
	case 5:
		total += 24;
		break;
	case 6:
		total += 50;
		break;
	}
	if(lav > 6)
		total += 100;
	total += sum;
	return total;
}

int rec(int x)
{
	return ((((__int64)x)*17235617 + 4311271) % 87465851);
}


int best_x = 1;
int best_dir = 1;
int res = 0;

void relax(int pos, int dir)
{
	int t = calcField(pos, dir);
	if(t > res)
	{
		res = t;
		best_x = pos;
		best_dir = dir;
	}
}

void brute()
{
	best_x = 1;
	best_dir = 1;
	res = 0;
	for (int i=1;i<=W;i++)
	{	
		relax(i, 1);
		relax(i, 3); 	
		if (i != 1)
		{
			relax(i, 2);
		}
		if(i != 8)
		{
			relax(i, 0);
		}
	}
}

int GetHeight(int pos)
	{
		for(int i = 1; i <= H; i++)
		{
			if(field[pos][i] == NIL)
				return i;
		}
		return H + 1;
	}


int main()
{
	//FILE* fr = fopen("pp.txt", "wt");
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
//#endif

	for(int i = 0 ; ; ++i)
	{
		char str[100];
		scanf("%s",str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) 
		{
			scanf("%d", &x0);
			col1 = x0 % 5 + 1;
			x0 = rec(x0);
			col2 = x0 % 5 + 1;
			printf("Tyumen SOGU\n");
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) 
		{
			for(int j = 0; j < H; j++)
				scanf("%s", &input[j]);
			for(int j = 0; j < H; j++)
				scanf("%*s");

			memset(field, 0, sizeof(field));
			for(int j = H-1; j >= 0; j--)
			{
				for (int k = 0; k < W; k++)
				{
					if (input[j][k] == '*')
						field[k+1][H - j] = BLACK;
					else if (input[j][k] >= '1' && '5' >= input[j][k])
						field[k+1][H - j] = input[j][k] - '0';
				}
			}
			brute();
			if(res == 0)
			{
				int min_h = H;
				int min_h_id = 1;
				for(int j = 1; j <= W; j++)
				{
					if(GetHeight(j) < min_h)
					{
						min_h = GetHeight(j);
						min_h_id = j;
					}
				}
				best_x = min_h_id;
				if(min_h_id < 8 && GetHeight(min_h_id + 1) == min_h)
					best_dir = 0;
				else if(min_h_id > 1 && GetHeight(min_h_id - 1) == min_h)
					best_dir = 2;
				else
					best_dir = 1;
			}
			
			/*for(int j = 0; j < H; j++)
			{
				for (int k=0;k<W;k++)
				{
				fprintf(fr, "%c", input[j][k]);
				}
				fprintf(fr, "\n");
			}
			fprintf(fr, "%d %d %d\n", best_x - 1, best_dir, res);
			fprintf(fr, "used colors : %d %d, xo = %d\n", col1, col2, x0);

			fflush(fr);*/
			
			printf("%d %d\n", best_x - 1, best_dir);
			x0 = rec(x0);
			col1 = x0 % 5 + 1;
			x0 = rec(x0);
			col2 = x0 % 5 + 1;
			fflush(stdout);
		}
	}
	//fclose(fr);
	return 0;
}
