#pragma comment(linker,"/STACK:16777216")

#define _CRT_SECURE_NO_DEPRECATE 1

#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <memory.h>
#include <string>
using namespace std;

const int inf = 1000*1000*1000;
const long long linf = ((long long) inf) * inf;

#define ALL(x)		(x).begin(), (x).end()
#define FOR(i,n)	for(int i=0;i<(int)(n);++i)
#define RFOR(i,n)	for(int i=(int)((n) - 1);i>=0;--i)
#define CL(x)		memset(x,0,sizeof(x))
#define CLX(x, v)	memset(x,v,sizeof(x))
#define MP			make_pair
#define PB			push_back

typedef long long LL;
typedef unsigned long long UL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;

////////////////////////////////////////////////////////////

//FILE * ff;

const char BotName[] = "Ninja_Prudaev_Attacker";

const int N = 1 << 20;
const int W = 8;
const int H = 16;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,-1,0,1};
int lenBonus[10];
vector<PII> allsteps;
void GenAllSteps()
{
	FOR(i, 8) FOR(j, 4)
	{
		if (i == 7 && (j == 0 || j == 2)) continue;
		allsteps.PB(MP(i, j));
	}
}

bool bound(int x, int y)
{
	return !(x < 0 || y < 0 || x >= H || y >= W);
}
struct Field
{
	int f[H][W];
	char u[H][W];
	char toCrash[H][W];

	int * operator [] (int i)
	{
		return f[i];
	}

	Field()
	{
		CL(f);
	}

	Field(char m[H][W + 5])
	{
		CL(f);
		FOR(y, H) FOR(x, W)
		{
			char c = m[y][x];
			if (c == '.') f[y][x] = 0;
			else if (c == '*') f[y][x] = 6;
			else f[y][x] = c - '0';
		}
	}
	int dfs1(int x, int y)
	{
		if (u[x][y] == 1)
			return 0;
		u[x][y] = 1;
		int res = 1;
		for (int i=0;i<4;i++)
		{
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (!bound(nx,ny) || f[nx][ny] != f[x][y])
				continue;
			res += dfs1(nx,ny);
		}
		return res;
	}
	void dfs2(int x, int y)
	{
		if (toCrash[x][y] == 1)
			return;
		toCrash[x][y] = 1;
		if (f[x][y] == 6)
			return;
		f[x][y] = 0;
		for (int i=0;i<4;i++)
		{
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (!bound(nx,ny))
				continue;
			if (!(f[nx][ny] == f[x][y] || f[nx][ny] == 6))
				continue;
			dfs2(nx,ny);
		}
	}
	void Crash()
	{
		for (int i=0;i<W;i++)
		{
			int p1=H-1,p2=H-1;
			while(p2 >= 0 && p1 >= 0)
			{
				if (f[p2][i] >= 1)
				{
					swap(f[p2][i],f[p1][i]);
					p1--;
				}
				p2--;
			}
		}
	}
	inline int Cool()
	{
		int Min = 10000;
		for (int i=0;i<W;i++)
		{
			int p = -1;
			while (p+1 <= H-1 && f[p+1][i] == 0)
				p++;
			Min = min(Min,p);
		}
		return Min;
	}
	int Relax(int &len)
	{
		CLX(u,0);
		CLX(toCrash,0);
		bool ok = 0;
		int res = 0;
		for (int i=0;i<H;i++)
		{
			for(int j=0;j<W;j++)
			{
				if (!u[i][j] && f[i][j] >= 1 && f[i][j] <= 5)
				{
					int t = dfs1(i,j);
					if (t >= 4)
					{
						res+= t-1;
						dfs2(i,j);
						ok = 1;
					}
				}
			}
		}
		if (ok)
		{
			len++;
			Crash();
			return res + Relax(len);
		}
		return 0;
	}
	pair<PII,PII> hui(PII fig, int pos, int rot)
	{
		PII a = MP(pos,fig.first);
		PII b = MP(0,fig.second);
		if (rot%2 == 0)
			b.first = pos+1;
		else
			b.first = pos;
		if (rot == 1 || rot == 2)
			swap(a.second,b.second);
		return MP(a,b);
	}
	inline bool Put(int pos, int col)
	{
		int p = -1;
		while(p+1 <= H-1 && f[p+1][pos] == 0)
			p++;
		if (p == -1)
			return 0;
		f[p][pos] = col;
		return 1;
	}
	inline bool Push(PII fig, int pos, int rot)
	{
		pair<PII,PII> t = hui(fig,pos,rot);
		return Put(t.first.first,t.first.second) && Put(t.second.first,t.second.second);
	}

};

int rnd[N];

inline void Init(int x0)
{
	rnd[0] = x0;
	for (int i = 1; i < N; i++) rnd[i] = (((LL) rnd[i - 1] * 17235617 + 4311271) % 87465851);
}

inline PII GetStep(int step)
{
	return MP((rnd[2 * step - 2] % 5) + 1, (rnd[2 * step - 1] % 5) + 1);
}
inline vector<int> getSomeSteps()
{
	vector<int> res;
	//FOR(i, 13) res.PB(rand() % allsteps.size());
	FOR(i, allsteps.size()) res.PB(i);
	return res;
}
inline pair<PII,int> Spread(Field f, int step, int d)
{
	if (d == 3)
		return MP(MP(0, 0), 100 * f.Cool());
	vector<int> v = getSomeSteps();
	int Max = -inf*2;
	PII X;
	for (int i=0;i<v.size();i++)
	{
		Field to = f;
		bool b = to.Push(GetStep(step),allsteps[v[i]].first,allsteps[v[i]].second);
		int len = 0;
		int z = 0;
		int t = to.Relax(len);
		if (len >= 7)
			z+=100;
		else z+=lenBonus[len];
		if (f.Cool() >= H/2+3)
			t+=z;
		t*=15;
		if (!b)
			t-=inf;
		pair<PII,int> q = Spread(to,step+1,d+1);
		t += q.second;
		if (t > Max)
		{
			Max = t;
			X = allsteps[v[i]];
		}
	}
	return MP(X,Max);
}
inline PII GetMove(Field f, int step)
{
	PII fig = GetStep(step);
	PII res = Spread(f,step,0).first;

	//

	/*FOR(i, H) {
		FOR(j, W) fprintf(ff, "%c", (char) (f.f[i][j] + '0'));
		fprintf(ff, "\n");
	}
	fprintf(ff, "---\n");
	fprintf(ff, "Push %d %d\n", fig.first, fig.second);
	fprintf(ff, "at %d %d\n", res.first, res.second);
	fprintf(ff, "---\n");
	*/
	//

	return res;
}

int main()
{
	lenBonus[0]=0;
	lenBonus[1]=0;
	lenBonus[2]=3;
	lenBonus[3]=6;
	lenBonus[4]=12;
	lenBonus[5]=24;
	lenBonus[6]=50;
	//ff = fopen("mylog.txt", "w");
	srand(2352333);
	for (int step = 1; ; )
	{
		static char buf[N];
		gets(buf);
		
		if(strcmp(buf, "Quit") == 0)
		{
			break;
		}
		else if(strcmp(buf, "Start") == 0)
		{
			int x0;
			gets(buf);
			sscanf(buf, "%d", &x0);

			Init(x0);
			GenAllSteps();
			printf("%s\n", BotName);
		}
		else if (strcmp(buf, "Move") == 0)
		{
			static char map1[H][W + 5];
			static char map2[H][W + 5];

			FOR(i, H)
			{
				gets(map1[i]);
				map1[i][W] = 0;
			}
			gets(buf);
			FOR(i, H)
			{
				gets(map2[i]);
				map2[i][W] = 0;
			}

			PII move = GetMove(Field(map1), step);
			printf("%d %d\n", move.first, move.second);

			step++;
		}

		fflush(stdout);
	} 
	return 0;
}
