#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

#ifdef _DEBUG
const int maxLevel=2;
#else
const int maxLevel=3;
#endif

const int w=8,h=16;
int posl[100000];

const int di[]={0,1,0,-1};
const int dj[]={1,0,-1,0};

struct Field
{
	char s[h][w+1];
};

istream& operator>>(istream& s,Field& f)
{
	for(int i=0;i<h;++i)
		s>>f.s[i];
	return s;
}

struct State
{
	Field me,he;
};

istream& operator>>(istream& s,State& ss)
{
	return s>>ss.me>>ss.he;
}

const int ii1[]={0,0,0,1};
const int jj1[]={0,0,1,0};
const int ii2[]={0,1,0,0};
const int jj2[]={1,0,0,0};

struct Move
{
	int l,r;
};

ostream& operator<<(ostream& s,const Move& m)
{
	return s<<m.l<<' '<<m.r;
}

inline bool ball(char c)
{
	return c!='.';
}

inline bool ballNotBlack(char c)
{
	return c>='1' && c<='5';
}

struct ApplyStat
{
	int regs,balls,blackBalls,steps;
	ApplyStat():regs(0),balls(0),blackBalls(0),steps(0){}
};

bool canMove(const Field& f,const Move& m)
{
	return
		m.l+jj1[m.r]<w &&
		m.l+jj2[m.r]<w &&
		f.s[ii1[m.r]][m.l+jj1[m.r]]=='.' &&
		f.s[ii2[m.r]][m.l+jj2[m.r]]=='.';
}

void fall(Field& f)
{
	bool anyFall=false;
	for(int j=0;j<w;++j)
	{
		int q=h-1;
		for(int i=h-1;i>=0;--i)
			if(ball(f.s[i][j]))
				f.s[q--][j]=f.s[i][j];
		for(int i=q;i>=0;--i)
			f.s[i][j]='.';
	}
}

ApplyStat apply(Field& f,const Move& m,int time)
{
	f.s[ii1[m.r]][m.l+jj1[m.r]]=posl[time*2]%5+'1';
	f.s[ii2[m.r]][m.l+jj2[m.r]]=posl[time*2+1]%5+'1';

	static int fl[h][w];
	static int qi[h*w],qj[h*w];
	static int color[h][w];
	ApplyStat stat;
	int hd,tl;
	for(;;)
	{
		fall(f);

		bool anyDestroy=false;
		for(int i=0;i<h;++i)
			fill(fl[i],fl[i]+w,0);
		for(int i=0;i<h;++i)
			for(int j=0;j<w;++j)
				if(ballNotBlack(f.s[i][j]) && !fl[i][j])
				{
					hd=tl=0;
					qi[tl]=i;
					qj[tl++]=j;
					fl[i][j]=1;
					while(hd<tl)
					{
						int ii=qi[hd];
						int jj=qj[hd++];
						for(int k=0;k<4;++k)
						{
							int iii=ii+di[k];
							int jjj=jj+dj[k];
							if(iii<0 || jjj<0 || iii>=h || jjj>=w || !ballNotBlack(f.s[iii][jjj]) || fl[iii][jjj] || f.s[iii][jjj]!=f.s[i][j])
								continue;
							qi[tl]=iii;
							qj[tl++]=jjj;
							fl[iii][jjj]=1;
						}
					}
					if(hd>=4)
					{
						stat.regs++;
						anyDestroy=true;
						for(int k=0;k<hd;++k)
						{
							int ii=qi[k];
							int jj=qj[k];
							f.s[ii][jj]='.';
							stat.balls++;
							for(int t=0;t<4;++t)
							{
								int iii=ii+di[t];
								int jjj=jj+dj[t];
								if(iii<0 || jjj<0 || iii>=h || jjj>=w || f.s[iii][jjj]!='*')
									continue;
								f.s[iii][jjj]='.';
								stat.blackBalls++;
							}
						}
					}
				}

		if(!anyDestroy) break;
		stat.steps++;
	}

	return stat;
}

inline double EvaluateLavina(int a)
{
	static double b[7]={0,0,3,6,12,24,50};
	return a<=6 ? b[a] : 100;
}

double Evaluate(const ApplyStat& stat,double enemyGood)
{
	return -enemyGood
		//бонус
		+2*(stat.balls-stat.regs-2)
		//
		+stat.blackBalls
		//
		+EvaluateLavina(stat.steps)
		;
}

int fieldEvaluate(const Field& f,bool precise)
{
	int good=0;
	for(int i=0;i<h;++i)
		for(int j=0;j<w;++j)
		{
			if(ball(f.s[i][j]))
			{
				good--;
				if(precise && f.s[i][j]!='*')
				{
					int c=0;
					for(int k=0;k<4;++k)
					{
						int ii=i+di[k];
						int jj=j+dj[k];
						if(ii<0 || jj<0 || ii>=h || jj>=w || f.s[ii][jj]!=f.s[i][j])
							continue;
						c++;
					}
					if(c>=2)
						good++;
				}
			}
		}
	return good;
}

bool calc(const State& s,int time,Move& move,double& good,int level)
{
	bool precise=level<maxLevel-1;
	good=fieldEvaluate(s.me,precise)-fieldEvaluate(s.he,precise);
	//оценка
	if(level>=maxLevel)
		return false;

	//подбор хода
	double moveGood=-0x3fffffff;
	Move bestMove;
	bestMove.l=0;
	bestMove.r=0;
	Move m;
	static int perl[]={3,4,2,5,1,6,0,7};
	for(int j=0;j<w;++j)
		for(m.r=0;m.r<4;++m.r)
		{
			m.l=perl[j];
			if(!canMove(s.me,m))
				continue;
			State s2=s;
			ApplyStat stat=apply(s2.me,m,time);
			swap(s2.me,s2.he);
			double good2;
			Move m2;
			calc(s2,time+1,m2,good2,level+1);
			good2=0.1*Evaluate(stat,good2);
			if(good2>moveGood)
			{
				moveGood=good2;
				bestMove=m;
			}
		}
	move=bestMove;
	good+=moveGood;
	return true;
}

void init(int x0)
{
	posl[0]=x0;
	for(int i=1;i<sizeof(posl)/sizeof(posl[0]);++i)
		posl[i]=(int)((posl[i-1]*1LL*17235617+4311271)%87465851);
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
#endif
	int time=0;
	for(int i = 0 ; ; ++i)
	{
		char str[100];
		cin>>str;
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			int x0;
			cin>>x0;
			init(x0);
			cout<<"Inception"<<endl;
		}
		else if(!strcmp(str,"Move")) {
			State s;
			cin>>s;
			fall(s.me);
			fall(s.he);
			Move m;
			double good;
			calc(s,time++,m,good,0);
			cout<<m<<endl;
		}
	}

	return 0;
}
