
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <vector>
using namespace std;
typedef long long li;
typedef pair<int,int> pi;
#define pb push_back
//#define int li
inline li next(li a){
	return (a*17235617+4311271) % 87465851;
}
inline char color(li a){
	return (char)((int)(a%5)+1+'0');
}
#define NOW ((li)bonus*1500+300*cnt-maxh-bad*15)
//vector<char> v[8];
char CurS[16][9];
bool used[16][8];
int height[8];
li bonus;
int cnt;

int dfs(int i,int j){
	if(CurS[i][j]<'1' || CurS[i][j]>'5')
		return 0;
	int r=1;
	used[i][j]=true;
	if(i>0 && CurS[i-1][j]==CurS[i][j] && !used[i-1][j]){
		r+=dfs(i-1,j);
	}
	if(i<15 && CurS[i+1][j]==CurS[i][j] && !used[i+1][j]){
		r+=dfs(i+1,j);
	}
	if(j>0 && CurS[i][j-1]==CurS[i][j] && !used[i][j-1]){
		r+=dfs(i,j-1);
	}
	if(j<7 && CurS[i][j+1]==CurS[i][j] && !used[i][j+1]){
		r+=dfs(i,j+1);
	}
	return r;
}
void operator +=( pi&  a,const pi& b){
	a.first+=b.first;
	a.second+=b.second;
}
pi zhah(int i,int j){
	pi r(1,0);
	char c=CurS[i][j];
	CurS[i][j]='.';
	if(i>0 && CurS[i-1][j]==c){
		r+=zhah(i-1,j);
	}
	if(i<15 && CurS[i+1][j]==c){
		r+=zhah(i+1,j);
	} 
	if(j>0 && CurS[i][j-1]==c){
		r+=zhah(i,j-1);
	}
	if(j<7 && CurS[i][j+1]==c){
		r+=zhah(i,j+1);
	}
	if(i>0 && CurS[i-1][j]=='*'){
		r.second+=1;
		CurS[i-1][j]='.';
	}
	if(i<15 && CurS[i+1][j]=='*'){
		r.second+=1;
		CurS[i+1][j]='.';
	}
	if(j>0 && CurS[i][j-1]=='*'){
		r.second++;
		CurS[i][j-1]='.';
	}
	if(j<7 && CurS[i][j+1]=='*'){
		r.second+=1;
		CurS[i][j+1]='.';
	}
	return r;
}
bool check_n_zhah(){
	memset(used,0,sizeof(used));
	bool r=false;
	for(int i=0;i<16;++i)
		for(int j=0;j<8;++j)
			if(!used[i][j] && dfs(i,j)>3){
				pi c=zhah(i,j);
				bonus+=c.first-1;
				cnt+=c.first+c.second*2;
				r=true;
			}
	return r;
}

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	//FILE* f;
	//f=fopen("debug2.txt","w");
	int w = 8, h = 16;
	li x0,x1;
	int i=0;
	while(true)
	{
		char str[100];
		scanf("%s",str);
		if(!strcmp(str,"Quit")){
		//	fclose(f);
		  break;
		}
		if(!strcmp(str,"Start")) {
			scanf("%lld", &x0);
			printf("RiaD\n");
			x1=next(x0);
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {
			//printf("Move %d\n",++i);
			char s[16][9];
			char cur[16][8];
			//vector<char> backupv[8];
			for(int j = 0; j < h; j++)
				scanf("%s",s[j]);
			for(int j = 0; j < h; j++)
				scanf("%*s");
			char FirstColor=color(x0),SecondColor=color(x1);
			/*for(int i=0;i<w;++i){
				for(int j=h-1;j>=0 && s[i][j]!='.';--j)
					backupv[i].pb(s[i][j]);
			}*/
			
			//printf("Xs:%lld %lld\n",x0,x1);
			//printf("Colors:%c %c\n",FirstColor,SecondColor);
			pi ans(0,0);
			li best=-1LL<<60;
			for(int Colon=0;Colon<w;++Colon){
				for(int pos=0;pos<4;++pos){
					for(int i=0;i<8;++i){
						height[i]=0;
						for(int j=h-1;j>=0 && s[j][i]!='.';--j)
							++height[i];
					}
					if(Colon==0 && pos==2) continue;
					if(Colon==7 && pos==0) continue;
					if(pos%2 && s[1][Colon]!='.') continue;
					if(s[0][Colon]!='.') continue;
					if((pos==0 || pos==2 ) && s[0][Colon-(pos-1)]!='.')continue;
					//memcpy(CurS,s,sizeof(s));
					for(int i=0;i<16;++i){
						memcpy(CurS[i],s[i],sizeof(s[i]));
					}
					/*for(int i=0;i<8;++i){
						v[i].assign(backupv[i].begin(),backupv[i].end());
					}*/
					bonus=0;
					cnt=0;
					if(pos==1)
						swap(FirstColor,SecondColor);
					int FirstColon=Colon;
					int SecondColon=FirstColon;
					if(pos==0)
						SecondColon++;
					else if(pos==2)
						SecondColon--;
					if(SecondColon>7)
						continue;
					if(SecondColon<0)
						continue;
					//v[FirstColon].pb(FirstColor);
					int bad=0;
					CurS[15-height[FirstColon]][FirstColon]=FirstColor;
					if(height[FirstColon] && CurS[15-height[FirstColon]][FirstColon]!=CurS[16-height[FirstColon]][FirstColon]){
						memset(used,0,sizeof(used));
						bad+=dfs(16-height[FirstColon],FirstColon);
					}
					++height[FirstColon];
					CurS[15-height[SecondColon]][SecondColon]=SecondColor;
					if(height[SecondColon] && CurS[15-height[SecondColon]][SecondColon]!=CurS[16-height[SecondColon]][SecondColon]){
						memset(used,0,sizeof(used));
						bad+=dfs(16-height[SecondColon],SecondColon);
					}
					++height[SecondColon];
					int c=0;
					int level=-1;
					do{
						c=0;
						++level;						
					
						c+=check_n_zhah();
						if(c){
							for(int j=0;j<8;++j){
								vector<char> v;
								for(int i=15;i>=0;--i)
									if(CurS[i][j]!='.')
										v.push_back(CurS[i][j]);
								int m=15;
								height[i]=0;
								for(int i=0;i<(int)v.size();++i){
									CurS[m--][j]=v[i];
									++height[i];
								}
								for(int i=m;i>=0;--i)
									CurS[i][j]='.';
							}
						}
					}
					while(c);
					li maxh=0;
					for(int i=0;i<8;++i)
							maxh+=height[i]*height[i];
					int bonuses[]={0,0,3,6,12,24,50,100};
					if(level>6)
						bonus+=100;
					else{
						bonus+=bonuses[level];
					}
					bonus-=2*level;
					if(pos==1)
						swap(FirstColor,SecondColor);
					if(NOW>best){
						best=NOW;
						if(pos==2)
							ans=pi(Colon-1,pos);
						else
							ans=pi(Colon,pos);
					}
					//printf("%d %d: %d\n",Colon,pos,bonus);
				}
			}
			//printf("%d %d\n", i % w, 1);
			printf("%d %d\n",ans.first,ans.second);
			//fprintf(f,"%d %d\n",ans.first,ans.second);
			//fflush(f);
			fflush(stdout);
			x0=next(x1);
			x1=next(x0);
		}
	}
	
	return 0;
}
