#pragma comment(linker, "/STACK:1000000000")
#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstring>
#include<set>
#include<map>
#include<ctime>
#include<climits>
#include<string>

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<char,char> pcc;

typedef vector<int> vi;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define y1 y1nvjksdngsd
#define y0 y0nvjksdngsd
#define next nextnvjksdngsd
#define ws wsnvjksdngsd
#define prev prevnvjksdngsd


const int w=8;
const int h=16;
ll x[10001];
char **a;
char **b;
char **t1, **t2;
char **t3;

char prot[20][20];

pi getball(int tk,int ds){
	return mp((int)(x[2*(tk+ds)-2]%5+1),(int)(x[2*(tk+ds)-1]%5+1));
}

void print(char** a) {
	for (int j=-2;j<h;j++){
		fprintf(stderr,"%s\n",a[j]);
	}
	fprintf(stderr,"\n");
}

void clear(char **a) {
	for (int i=-2;i<=h;i++)
		for (int j=0;j<w;j++)
			a[i][j] = '.';
	for (int i=-2;i<=h;i++)
		a[i][w] = 0;
}

void cp(char** a, char** b) {
	for (int i=-2;i<=h;i++)
		for (int j=0;j<=w;j++)
			b[i][j] = a[i][j];
}

bool fall(char** a, char** b) {
	int cnt;
	bool fl = false;
	clear(b);
	for (int i=0;i<w;i++)	{
		cnt = 0;
		for (int j=h-1;j>=-2;j--)
			if (a[j][i]=='.') cnt++; else { 
				b[j+cnt][i] = a[j][i];
				if (cnt>0) fl = true;
			}
	}
	return fl;
}

int cnt,tk;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int ws[40][40];
int ws2[40][40];
void dfs(char ** a,int x,int y,char cc){
	if (x<-2 || x>=h || y<0 || y>=w) return;
	if (ws[x+2][y]!=0 || a[x][y]!=cc){
		return;
	}
//	cerr<<x<<" "<<y<<endl;
    cnt++;
    ws[x+2][y]=1;
    for (int i=0;i<4;i++)
    	dfs(a,x+dx[i],y+dy[i],cc);	
} 
void dfs2(char ** a,int x,int y,char cc){
	if (x<-2 || x>=h || y<0 || y>=w) return;
	if (ws2[x+2][y]==0 && a[x][y]=='*'){
		ws2[x][y]=1;
		a[x][y]='.';
		return;
	}
	if (ws2[x+2][y]!=0 || a[x][y]!=cc){
		return;
	}
    ws2[x+2][y]=1;
	a[x][y]='.';
    for (int i=0;i<4;i++)
    	dfs2(a,x+dx[i],y+dy[i],cc);	
} 



int expl(char **a, char** b,bool& fl) {
	cp(a,b);
	for (int i=0;i<h+2;i++)
		for (int j=0;j<w;j++) {
			ws[i+2][j]=0;
			ws2[i+2][j]=0;
		}
	tk=0;
	int ttk=0;
	for (int i=-2;i<h;i++)
		for (int j=0;j<w;j++) if (ws[i+2][j]==0 && a[i][j]!='.' && a[i][j]!='*'){
			cnt=0;
			dfs(a,i,j,a[i][j]);
//			cerr<<endl;
			if (cnt>=4){
				tk+=cnt-1;
				dfs2(b,i,j,a[i][j]);
			} else {
				ttk+=cnt;
			}
		}
	fl=(tk==0);
	return max(tk-2,0)*10+ttk;
}

bool lose(char** a) {
	for (int i=-2;i<=-1;i++)
		for (int j=0;j<w;j++)
			if (a[i][j]!='.') return true;
	return false;
}

int model(char** a, char** b , pi cl,pi ps){
//	cerr << "!model" << endl;
//	cerr << cl.fs << " " << cl.sc << endl;
	cp(a, t1);
	if (ps.sc==0) {
		t1[-1][ps.fs] = '0'+cl.fs;
		t1[-1][ps.fs+1] = '0'+cl.sc;
	}
	if (ps.sc==1) {
		t1[-2][ps.fs] = '0'+cl.fs;
		t1[-1][ps.fs] = '0'+cl.sc;
	}

	if (ps.sc==2) {
		t1[-1][ps.fs] = '0'+cl.sc;
		t1[-1][ps.fs+1] = '0'+cl.fs;
	}

	if (ps.sc==3) {
		t1[-2][ps.fs] = '0'+cl.sc;
		t1[-1][ps.fs] = '0'+cl.fs;
	}

	bool fl1,fl2;
	int ans=0,kx,pls;
	kx=0;
	while (1) {
//		cerr<<"tiktik"<<endl;
		fl1 = fall(t1, t2);
//		cerr<<fl1<<endl;
		pls = expl(t2, t1,fl2);
//		cerr<<pls<<endl;
		ans+=pls;
		if (pls>0) kx++;
		if (!fl1 && fl2) break;		
	}
	if (kx==1) ans+=0;
	if (kx==2) ans+=3;
	if (kx==3) ans+=6;
	if (kx==4) ans+=12;
	if (kx==5) ans+=24;
	if (kx==6) ans+=50;
	if (kx>=7) ans+=100;


	if (lose(t1)) {
		return -100000;
	}
/*	for (int i=0;i<h;i++)
		for (int j=0;j<w;j++)
			if (t1[i][j]!='.'){
				return ans+i*3;
			}                  */
	return ans;		
}

pi play1(int tkxod){
	model(a,b,getball(tkxod,0),mp(0,1));
	cerr << "after!" << endl;
	print(b);
	return mp(0,1);		
}

int g[8]={3, 1, 3, 1, 1, 1, 3, 3};
int g2[8]={1, 2, 3, 4, 1, 1, 3, 2};
pcc getball2(int t){
	pi g= getball(t, 0);
	return mp(g.fs+'0', g.sc+'0');
}
pi rev(pi r, int nr){
	if(nr==1){
		if(r.sc==0){
			r.fs++;
			r.sc=2;
		}else
		if(r.sc==1){
			r.sc=3;
		}else
		if(r.sc==2){
			r.fs--;
			r.sc=0;
		}else
		if(r.sc==3){
			r.sc=1;
		}
	}
	return r;
}
char getcl(int f){
	for(int i=0;i<h;i++) if(a[i][f]!='.'){
		if(a[i][f]>='1' && a[i][f]<='5') return a[i][f];
		else return '0';
	}
	return '0';
}

int geth(int f){
	for(int i=h-1;i>=1;i--) if(a[i][f]=='.') return i;
	return 1;
}

pi play2(int t){
	pcc r=getball2(t);
	int nr=0;
	if(r.fs>r.sc){
		swap(r.fs, r.sc);
		nr=1;
	}
	int sd=-1;
	if(r.fs=='1' && r.sc=='1') sd=4;
	if(r.fs=='2' && r.sc=='2') sd=0;
	if(r.fs=='3' && r.sc=='3') sd=5;
	if(r.fs=='4' && r.sc=='4') sd=2;
	if(r.fs=='5' && r.sc=='5') sd=6;
	if(sd>=0){
		int c1=model(a, t3, getball(t, 0), rev(mp(sd, 0), nr));
		int c2=model(a, t3, getball(t, 0), rev(mp(sd, 1), nr));
        int c3=model(a, t3, getball(t, 0), rev(mp(sd+1, 1), nr));
        int c=max(c1, max(c2, c3));
        if(c1==c) return rev(mp(sd, 0), nr);
        if(c2==c) return rev(mp(sd, 1), nr);
        if(c3==c) return rev(mp(sd+1, 1), nr);
        return rev(mp(sd, 0), nr);
    }	
	int h=0;
	if(r.fs=='1' && r.sc=='2') h=0;
	if(r.fs=='2' && r.sc=='3') h=1;
	if(r.fs=='3' && r.sc=='4') h=2;
	if(r.fs=='4' && r.sc=='5') h=3;
	if(r.fs=='1' && r.sc=='5') h=4;
	if(r.fs=='1' && r.sc=='3') h=5;
	if(r.fs=='3' && r.sc=='5') h=6;
	if(r.fs=='2' && r.sc=='5') h=7;
	
	if(r.fs=='2' && r.sc=='4') return rev(mp(1, 0), nr);
	if(r.fs=='1' && r.sc=='4') return rev(mp(4, 2), nr);

	//g[h]=4-g[h];
	char gg=getcl(h);
	if(gg=='0'){
		int c3=model(a, t3, getball(t, 0), rev(mp(h, 3), nr));
		int c1=model(a, t3, getball(t, 0), rev(mp(h, 1), nr));
		if(c1>c3) return rev(mp(h, 1), nr);
		else if(c1==c3) return rev(mp(h, g[h]), nr);
		else return rev(mp(h, 3), nr);
	}
	//cerr<<gg<<" "<<r.fs<<endl;
	if(gg==r.fs) return rev(mp(h, 3), nr);
	else return rev(mp(h, 1), nr);
}
		


		
	
	
	

int main()
{
//	freopen("mylog.txt","w",stderr);
	//cerr<<"sjkdgfkb\n";
	a = new char*[22];
	b = new char*[22];
	t1 = new char*[22];
	t2 = new char*[22];
	t3 = new char*[22];


	for(int i=0;i<22;i++) a[i]=new char[20];
	for(int i=0;i<22;i++) b[i]=new char[20];
	for(int i=0;i<22;i++) t1[i]=new char[20];
	for(int i=0;i<22;i++) t2[i]=new char[20];
	for(int i=0;i<22;i++) t3[i]=new char[20];
	a+=2; b+=2; t1+=2; t2+=2; t3+=2;

	clear(a);
	for(int i = 0 ; ; ++i)
	{
		char str[100];
		scanf("%s",str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			int x0;
			scanf("%d", &x0);
			x[0]=x0;
			for (int i=1;i<=10000;i++){
				x[i]=(x[i-1]*17235617+4311271)%87465851;
			}
			printf("SPbSU_Invasion\n");
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {
			for(int j = 0; j < h; j++)
				scanf("%s",a[j]);
	//		cerr << "new move" << endl;
	//		print(a);
			for(int j = 0; j < h; j++)
				scanf("%s",prot[j]);
			pi ans=play2(i);
			printf("%d %d\n", ans.fs, ans.sc);
			fflush(stdout);
		}
	}

	return 0;
}
