#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int dx [4]= {-1,1,0,0};
const int dy [4]= {0,0,1,-1}; 

const int w = 8, h = 16;
int x0,x1;
char my_grid[h+3][w+3], enemy_grid[h+3][w+3];


struct S_point{
	int x,y;
};

int next_X(long long xi){
	return (xi * 17235617 + 4311271)%87465851;
}

void func_x(int x0, int &x1, int &x2){
	x1 = next_X(x0);
	x2 = next_X(x1);
}

int BFS(S_point a, S_point not_a, bool &touch){
	if(a.x<0 || not_a.x<0)
		return 0;
	touch = false;
	bool used[h][w];
	memset(used,0,sizeof(used));
	int sum = 0;
	queue <S_point> my_que;
	used[a.x][a.y] = true;
	my_que.push(a);
	while(!my_que.empty())
	{
		
		S_point tmp = my_que.front();
		my_que.pop();
		if(a.x != tmp.x || a.y != tmp.y )
			sum++;
		for(int i=0;i <4; i++){
			int tx = tmp.x + dx[i];
			int ty = tmp.y + dy[i];
			if(tx>=0 && tx<h && ty>=0 && ty<w){
				if(my_grid[tx][ty]==my_grid[a.x][a.y] && !used[tx][ty]){
					if(tx==not_a.x && ty==not_a.y)
						touch = true;
					S_point tt;
					tt.x = tx;
					tt.y = ty;
					used[tx][ty] = true;
					my_que.push(tt);
				}
			}
		}
	}

	return sum;
}
void calc(){
	int best_s =rand()%7, best_r=rand()%4, value = 0,hx[2]={0,0};
	/*while(best_s==7 && (best_r==0 || best_r==2)){
		best_s =rand()%8;
		best_r=rand()%4;
	}*/
	for(int i = 0; i<=7 ; i++){
		for(int j=0; j <=3; j++){
			if(i!=7 || j!=0 && j!=2){
				int t[2];
				if( (j==1) || (j==2)){
					t[0] = x1;
					t[1] = x0;
				}
				else{
					t[0] = x0;
					t[1] = x1;
				}
				S_point pos[2];
				pos[0].y = i;
				pos[1].y = (j==1||j==3) ? i : i+1; 
				for(int l = 0; l<2; l++){
					int tmp_x = 0;
					while(tmp_x+1<h && my_grid[tmp_x+1][pos[l].y]=='.')
						tmp_x++;
					pos[l].x = tmp_x;
					my_grid[pos[l].x][pos[l].y] = t[l]+'0';
				}
				bool touch;
				int tmp_val = BFS(pos[0],pos[1],touch);

				if(!touch)
					tmp_val+= BFS(pos[1],pos[0],touch);
				
				if(tmp_val == value){
					if(hx[0]+hx[1]< pos[0].x+pos[1].x){
						value = tmp_val;
						best_s = i;
						best_r = j;
						hx[0] = pos[0].x;
						hx[1] = pos[1].x;
					}
				}
				else{
					if(tmp_val>value){
						value = tmp_val;
						best_s = i;
						best_r = j;
						hx[0] = pos[0].x;
						hx[1] = pos[1].x;
					}
				}
				for(int l = 0; l<2; l++){
					my_grid[pos[l].x][pos[l].y] ='.';
				}
			}
		}
	}
	printf("%d %d\n", best_s, best_r);
	fflush(stdout);

}

int main()
{
	
	for(int i = 0 ; ; ++i)
	{
		char str[100];
		scanf("%s",str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			scanf("%d", &x0);
			srand(x0);
			x1 = next_X(x0);
			printf("PSU3_Bot\n");
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {
			for(int j = 0; j < h; j++)
				scanf("%s",my_grid[j]);

			for(int j = 0; j < h; j++)
				scanf("%s",enemy_grid[j]);
			 

			int last_x = x1;
			x0%=5;
			x0++;
			x1%=5;
			x1++;
			calc();
			//printf("0 2\n");
			//fflush(stdout);
			func_x(last_x,x0,x1);
		}
	}

	return 0;
}
