#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>

const int w = 8, h = 16;
char  field[2*h][w];
char misc[h+1][w+1];

int x0, x1, _x1, _x2;

long long x[50];

int counter=0;
int move=0;
int maxcounter=0;
int	max_h=0;
int max_w=0;

int w_h=0;
int w_w=0;

void dfs (int _h, int _w, int colour);
int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("in.txt", "rt", stdin);
	freopen("out.txt", "wt", stdout);
#endif //ONLINE_JUDGE*/
	
	srand(time(NULL));
	for(int i = 0 ; ; ++i)
	{
		char str[100];
		scanf("%s", str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) 
		{
			scanf("%d", &x0);
			printf("Misery\n");
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) 
		{
			move++;
			int i;
			if ((move%50)==1)
				if (move==1)
					for (i=0; i<50; i++)
						if (i==0)
							x[i]=(x0*17235617+4311271)%87465851;
						else
							x[i]=(x[i-1]*17235617+4311271)%87465851;
				else
					for (i=0; i<50; i++)
						if (i==0)
							x[i]=(x[49]*17235617+4311271)%87465851;
						else
							x[i]=(x[i-1]*17235617+4311271)%87465851;
			for(int i = 0; i < h; i++)
					scanf("%s", &field[h-i-1]);
			//scanf("%s");
			for(int i = 16; i < 2*h; i++)
					scanf("%s", &field[2*h-i-1]);
			for (int i=0; i<8; i++)
			{
				for (int k=0; k<h; k++)
				{
					if (field[k][i])
						for (int j=0; j<2; j++)
						{
							counter=0;
							dfs(k, i, x[move%50-1+j]);
						if (maxcounter<=counter)
						{
							maxcounter=counter;
							max_h=k;
							max_w=i;
						}
						}
				}
			}
			
			if (counter==2)
				max_w=rand()%8;
			int k=3;
			if ((max_w>1)&&(max_w<6))
				if (rand()%2)
					k=0;
				else
					k=2;
			printf("%d %d\n", max_w, k);
			fflush(stdout);
		}
	}

	return 0;
}



void dfs (int _h, int _w, int colour)
{
	
	if (!counter)
	{		
		for (int i=0; i<h; i++)
			for (int j=0; j<w; j++)
				misc[i][j]=0;
		misc[_h][_w]=1;
		counter++;
	}
	misc[_h][_w]=counter++;
	if ((_w-1>=0)&&(field[_h][_w-1]==colour)&&(misc[_h][_w]==0))
		dfs(_h,_w-1, colour);
	if ((_w+1<8)&&(field[_h][_w+1]==colour)&&(misc[_h][_w]==0))
		dfs(_h,_w+1, colour);
	if ((_h+1<16)&&(field[_h+1][_w]==colour)&&(misc[_h][_w]==0))
		dfs(_h+1,_w, colour);
	if ((_h-1>=0)&&(field[_h-1][_w]==colour)&&(misc[_h][_w]==0))
		dfs(_h-1,_w, colour);
}