#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <stdio.h>

#define NONE 0
#define BLACK -1
#define w 8
#define h 16

using namespace std;

class Field
{
	int field[h][w];
public:
	void read();
	vector<int> balls();//destroyed balls,destroyed black balls,bonus for enemy
	int fallDown(int c1,int c2,int x,int state);
	Field& operator=(const Field& f);
};

bool isCorrect(int x,int y)
{
	return (x>=0&&x<w&&y>=0&&y<h);
}

Field& Field::operator=(const Field& f)
{
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			field[i][j]=f.field[i][j];
	return *this;
}

int Field::fallDown(int c1,int c2,int x,int state)
{
	int x1,x2,y1,y2;
	switch(state)
	{
	case 0:
		{
		y1=h;
		for(int i=h-1;i>=0;i--)
			if(field[i][x]!=NONE)
				break;
			else
				y1--;
		if(y1==h)return -1;
		y2=h;
		for(int i=h-1;i>=0;i--)
			if(field[i][x+1]!=NONE)
				break;
			else
				y2--;
		if(y2==h)return -1;
		x1=x;x2=x+1;
		field[y1][x]=c1;
		field[y2][x+1]=c2;
		break;
		}
	case 1:
		{
		int y=h;
		for(int i=h-1;i>=0;i--)
			if(field[i][x]!=NONE)
				break;
			else
				y--;
		if(y>=h-1)return -1;		
		y1=y+1;
		y2=y;
		x1=x2=x;
		field[y+1][x]=c1;
		field[y][x]=c2;
		break;
		}

	case 2:
		{
		y1=h;
		for(int i=h-1;i>=0;i--)
			if(field[i][x+1]!=NONE)
				break;
			else
				y1--;
		if(y1==h)return -1;
		y2=h;
		for(int i=h-1;i>=0;i--)
			if(field[i][x]!=NONE)
				break;
			else
				y2--;
		if(y2==h)return -1;
		x1=x+1;
		x2=x;
		field[y1][x+1]=c1;
		field[y2][x]=c2;
		/*int tmp=y1;
		y1=y2;
		y2=tmp;*/
		break;
		}

	case 3:
		{
		int y=h;
		for(int i=h-1;i>=0;i--)
			if(field[i][x]!=NONE)
				break;
			else
				y--;
		if(y>=h-1)return -1;		
		y2=y+1;
		y1=y;
		x1=x2=x;
		field[y+1][x]=c2;
		field[y][x]=c1;
		break;
		}
	}
	int dx[4]={-1,1,0,0};
	int dy[4]={0,0,-1,1};
	int free1=0;
	for(int i=0;i<4;i++)
	{
		int newx=x1+dx[i];
		int newy=y1+dy[i];
		if(isCorrect(newx,newy)&&field[newy][newx]==NONE)
			{
				//free1++;
				if(i==1)free1++;
			}
	}
	int free2=0;
	for(int i=0;i<4;i++)
	{
		int newx=x2+dx[i];
		int newy=y2+dy[i];
		if(isCorrect(newx,newy)&&field[newy][newx]==NONE){
				//free2++;
				if(i==1)free2++;
			}
	}
	int size1=0;
	queue<int> q;
	q.push(x1*h+y1);
	bool used[h][w];
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			used[i][j]=false;
	used[y1][x1]=true;
	while(!q.empty())
	{
		int cur=q.front();
		int y=cur/h;
		int x=cur%h;
		q.pop();
		size1++;
		for(int i=0;i<4;i++)
		{
			int newx=x+dx[i];
			int newy=y+dy[i];
			if(isCorrect(newx,newy)&&field[newy][newx]==c1&&!used[newy][newx])
			{
				q.push(newx*h+newy);
				used[newy][newx]=true;
			}
				
		}
	}
	int size2=0;
	if(c1!=c2)
	{
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			used[i][j]=false;
		used[y2][x2]=true;
		while(!q.empty())
		{
			int cur=q.front();
			int y=cur/h;
			int x=cur%h;
			q.pop();
			size2++;
			for(int i=0;i<4;i++)
			{
				int newx=x+dx[i];
				int newy=y+dy[i];
				if(isCorrect(newx,newy)&&field[newy][newx]==c2&&!used[newy][newx])
				{
					q.push(newx*h+newy);
					used[newy][newx]=true;
				}
				
			}
		}
	}
#ifdef LOG
	cerr<<size1<<' '<<size2<<' '<<free2<<endl;
#endif
	return (size1+size2)*3+free1+free2;

}

void Field::read()
{
	for(int j = h-1; j >= 0 ; j--)
	{
		string s;
		cin>>s;
		for(int k=0;k<w;k++)
		{
			if(s[k]=='.')
				field[j][k]=NONE;
			else
				if(s[k]=='*')
					field[j][k]=BLACK;
				else
					field[j][k]=s[k]-'0';
		}
	}
}

vector<int> Field::balls()
{
	int res=0;
	int myBlack=0;
	int l=0;
	int blackForEnemy=0;
	bool cont=false;
	//cerr<<"step1"<<endl;
	do
	{
		l++;
		cont=false;
		int  area[h][w];
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				area[i][j]=field[i][j]==NONE?-2:-1;
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
			{
				if(area[i][j]==-1)
				{
					queue<int> q;
					q.push(i*h+j);
					area[i][j]=1;
					while(!q.empty())
					{
						int cur=q.front();
						int x=cur/h;
						int y=cur%h;
						q.pop();
						int dx[4]={-1,1,0,0};
						int dy[4]={0,0,-1,1};
						for(int k=0;k<4;k++)
						{
							int nx=x+dx[k];
							int ny=y+dy[k];
							if(nx>=0&&nx<h&&ny>=0&&ny<w&&field[nx][ny]==field[x][y]&&area[nx][ny]==-1)
							{
								q.push(nx*h+ny);
								area[nx][ny]=area[x][y]+1;
							}
						}
					}
				}
			}
			//cerr<<"step2"<<endl;
		int b=0;
		int a=0;
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
			{
				if(area[i][j]>=4&&field[i][j]!=NONE)
				{
					cont=true;

					queue<int> q;
					q.push(i*h+j);
					int color=field[i][j];
					field[i][j]=NONE;
					while(!q.empty())
					{
						b++;
						res++;
						int cur=q.front();
						int x=cur/h;
						int y=cur%h;
						q.pop();
						int dx[4]={-1,1,0,0};
						int dy[4]={0,0,-1,1};
						for(int k=0;k<4;k++)
						{
							int nx=x+dx[k];
							int ny=y+dy[k];
							if(nx>=0&&nx<h&&ny>=0&&ny<w&&(field[nx][ny]==color||field[nx][ny]==BLACK))
							{
								if(field[nx][ny]==BLACK)
								{
									myBlack++;
									//b--;
								}
								else
									q.push(nx*h+ny);
								field[nx][ny]=NONE;
							}
						}
					}
					a++;
				}
			}
		if(b>0)
			blackForEnemy+=(b-a-2);
		//cerr<<"step3"<<endl;
		for(int j=0;j<w;j++)
		{
			int deep=0;
			for(int i=0;i<h;i++)
				if(field[i][j]==NONE)
					deep++;
				else
				{
					field[i-deep][j]=field[i][j];
					field[i][j]=NONE;
				}
		}
	}
	while(cont);
	int bonus[9]={0,0,0,3,6,12,24,50,100};
	if(l>8)l=8;
	blackForEnemy+=bonus[l];
	vector<int> r;
	r.push_back(res);
	r.push_back(myBlack);
	r.push_back(blackForEnemy);

	return r;
}

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

int main()
{
	int x0;
	Field my,enemy;
	//freopen("input.txt","rt",stdin);
#ifdef LOG
	freopen("log.txt","wt",stderr);
#endif
	int next=0;
	for(int i = 0 ; ; ++i)
	{
		string com;
		cin>>com;
		if(com=="Quit")
		  break;
		if(com=="Start") {
			cin>>x0;
			cout<<"Hindoo\n";
			cout.flush();
		}
		else if(com=="Move") {
			my.read();
			string s;
			enemy.read();
			int scores[w][4];
			int bestx=next,beststate=0;
			int max=-1;
			next=(next+2)%7;
			vector<int> bestres;
			bestres.push_back(0);
			bestres.push_back(0);
			bestres.push_back(0);
			int c1=x0%5;
			x0=nextX(x0);
			int c2=x0%5;
			x0=nextX(x0);
			for(int j=0;j<w;j++)
				for(int k=0;k<4;k++)
				{
					if(j==w-1&&(k==0||k==2)){scores[j][k]=-1;continue;}
					Field tmp;
					tmp=my;
					scores[j][k]=tmp.fallDown(c1,c2,j,k);
					if(scores[j][k]!=-1)
					{
						vector<int> curRes=tmp.balls();
						for(int e=0;e<3;e++)
						{
							scores[j][k]+=curRes[e]*(4-e);
						}
						if(scores[j][k]>max)max=scores[j][k];
					}
				}
#ifdef LOG
			cerr<<max<<endl;
#endif
			if(max==-1)
				cout<<"0 0\n";
			else
			{
				vector<int> bestj;
				vector<int> bestk;
				for(int j=0;j<w;j++)
					for(int k=0;k<4;k++)
						if(scores[j][k]==max)
						{
							#ifdef LOG
				cerr<<"vect:"<<j<<' '<<k<<endl;
#endif
							bestj.push_back(j);
							bestk.push_back(k);
						}

#ifdef LOG
				cerr<<"step:"<<bestj.size()<<' '<<bestj[0]<<' '<<bestk[0]<<endl;
#endif
				cout<<bestj[0]<<' '<<bestk[0]<<'\n';
			}
			cout.flush();
		}
	}

	return 0;
}
