#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

char str[100];
char **f_u;
char **f_v;
int x0, step, c1, c2;
int pgggg[4];
int oldpgggg[4];

struct point
{
	int x, y;
	point(int vX = 0, int vY = 0)
	{
		x = vX;
		y = vY;
	}
};

point d[4] = {point(1, 0), point(0, 1), point(-1, 0), point(0, -1)};

inline point operator+ (const point& a, const point& b)
{
	return point(a.x + b.x, a.y + b.y);
}

inline bool good(point p)
{
	return (p.x >= 0 && p.x < 16 && p.y >= 0 && p.y < 8);
}

int bfs(char** f, bool** u, point p)
{
	int res = 1;
	queue<point> q;
	u[p.x][p.y] = 1;
	q.push(p);
	while(!q.empty())
	{
		point t = q.front();
		q.pop();
		for(int i = 0; i < 4; i++)
		{
			point np = t + d[i];
			if(good(np) && !u[np.x][np.y] && f[p.x][p.y] == f[np.x][np.y])
			{
				u[np.x][np.y] = 1;
				q.push(np);
				res++;
			}
		}
	}
	return res;
}

vector<pair<point, int> > findBooms(char** f)
{
	bool **use = new bool*[16];
	for(int i = 0; i < 16; i++)
	{
		use[i] = new bool[8];
		for(int j = 0; j < 8; j++)
		{
			use[i][j] = 0;
		}
	}
	vector<pair<point, int> > ps;
	for(int i = 0; i < 16; i++)
	{
		for(int j = 0; j < 8; j++)
		{
			if(f[i][j] != '.' && !use[i][j])
			{
				point t(i, j);
				int cnt = bfs(f, use, t);
				if(cnt < 4)
				{
					pgggg[cnt]++;
				}
				if(cnt >= 4)
				{
					ps.push_back(make_pair(t, cnt));
				}
			}
		}
	}
	for(int i = 0; i < 16; i++)
	{
		delete[] use[i];
	}
	delete[] use;
	return ps;
}

void down(char** f)
{
	for(int j = 0; j < 8; j++)
	{
		int pos = 15;
		for(int i = 15; i >= 0; i--)
		{
			if(f[i][j] != '.')
			{
				if(i != pos)
				{
					f[pos][j] = f[i][j];
					f[i][j] = '.';
				}
				--pos;
			}
		}
	}
}

int getH(char** f, int j)
{
	int len = 0;
	while(len < 16 && f[len][j] == '.')
		len++;
	return 16 - len;
}

int getH(char** f)
{
	int maxH = 0;
	for(int j = 0; j < 8; j++)
	{
		int len = getH(f, j);
		maxH = maxH > len ? maxH : len;
	}
	return maxH;
}

int getBlacks(char** f)
{
	int res = 0;
	for(int i = 0; i < 16; i++)
	{
		for(int j = 0; j < 8; j++)
		{
			if(f[i][j] == '*')
				res++;
		}
	}
	return res;
}

int clear(char** f, point p)
{
	int res = 0;
	bool u[16][16];
	memset(u, 0, sizeof(u));
	vector<point> dp;
	queue<point> q;
	u[p.x][p.y] = 1;
	dp.push_back(p);
	q.push(p);
	while(!q.empty())
	{
		point t = q.front();
		q.pop();
		for(int i = 0; i < 4; i++)
		{
			point np = t + d[i];
			if(good(np) && !u[np.x][np.y] && f[p.x][p.y] == f[np.x][np.y])
			{
				u[np.x][np.y] = 1;
				q.push(np);
				dp.push_back(np);
			}
			if(good(np) && !u[np.x][np.y] && '*' == f[np.x][np.y])
			{
				u[np.x][np.y] = 1;
				res++;
				dp.push_back(np);
			}
		}
	}
	for(int i = 0; i < dp.size(); i++)
	{
		f[dp[i].x][dp[i].y] = '.';
	}
	return res;
}

//<длина лавины, бонус>
void boom(char** f, int& blackDie, int& bonusLen, int& bonusDie, int& allDie)
{
	bonusLen = 0;
	blackDie = 0;
	int len = 0;
	allDie = 0;
	bonusDie = -2;
	while(1)
	{
		vector<pair<point, int> > ps = findBooms(f);
		if(ps.empty())
			break;
		len++;
		for(int i = 0; i < ps.size(); i++)
		{
			bonusDie += ps[i].second;
			int cnt = clear(f, ps[i].first);
			allDie += ps[i].second + cnt;
			blackDie += cnt;
		}
		bonusDie--;
		down(f);
	}
	switch(len)
	{
	case 0:
		bonusLen = 0;
		bonusDie = 0;
		break;
	case 1:
		bonusLen = 0;
		break;
	case 2:
		bonusLen = 3;
		break;
	case 3:
		bonusLen = 6;
		break;
	case 4:
		bonusLen = 12;
		break;
	case 5:
		bonusLen = 24;
		break;
	case 6:
		bonusLen = 50;
		break;
	default:
		bonusLen = 100;
		break;
	}
}

bool downFig(char** f, char** g)
{
	for(int j = 0; j < 8; j++)
	{
		int pos = 0;
		while(pos < 16 && f[pos][j] == '.')
		{
			pos++;
		}
		if(g[1][j] == '.')
		{
			g[1][j] = g[0][j];
			g[0][j] = '.';
		}
		for(int i = 1; i >= 0; i--)
		{
			if(g[i][j] != '.')
			{
				if(pos == 0)
					return 0;
				f[--pos][j] = g[i][j];
			}
		}
	}
	return 1;
}

int getX()
{
	int res = x0;
	x0 = (((long long)x0) * 17235617 + 4311271) % 87465851;
	return res;
}

 //- exp(1.0) * blackCount * blackCount)

int calc(int blackDie, int bonusLen, int bonusBoom, int allDie, int H, int blackCount)
{
	return (int)((((acos(-1.0) * bonusBoom * bonusBoom)) + (exp(1.0) * blackDie * blackDie)) +
		((1 + sqrt(5.0)) / 2.0 * (max(0, pgggg[3] - oldpgggg[3]))));
}

int mark(char** f, int s, int r)
{
	memset(pgggg, 0, sizeof(pgggg));
	char old[16][16];
	for(int i = 0; i < 16; i++)
	{
		for(int j = 0; j < 16; j++)
		{
			old[i][j] = f_u[i][j];
		}
	}
	char** g = new char*[2];
	g[0] = new char[16];
	g[1] = new char[16];
	for(int i = 0; i < 2; i++)
	{
		for(int j = 0; j < 8; j++)
		{
			g[i][j] = '.';
		}
	}
	switch(r)
	{
	case 0:
		g[1][s] = '0' + c1;
		g[1][s + 1] = '0' + c2;
		if(s + 1 >= 8)
			return -1e9;
		break;
	case 1:
		g[1][s] = '0' + c1;
		g[0][s] = '0' + c2;
		break;
	case 2:
		g[1][s] = '0' + c2;
		g[1][s + 1] = '0' + c1;
		if(s + 1 >= 8)
			return -1e9;
		break;
	case 3:
		g[1][s] = '0' + c2;
		g[0][s] = '0' + c1;
		break;
	}
	if(!downFig(f, g))
		return -1e9;
	int a, b, c, d;
	boom(f, a, b, c, d);
	int res = calc(a, b, c, d, getH(f), getBlacks(f));
	for(int i = 0; i < 16; i++)
	{
		for(int j = 0; j < 16; j++)
		{
			f_u[i][j] = old[i][j];
		}
	}
	return res;
}



int main()
{
	memset(pgggg, 0, sizeof(pgggg));
	srand(1);
	f_u = new char*[16];
	for(int i = 0; i < 16; i++)
	{
		f_u[i] = new char[16];
	}
	f_v = new char*[16];
	for(int i = 0; i < 16; i++)
	{
		f_v[i] = new char[16];
	}
	step = 0;
	int w = 8, h = 16;
	for(;;)
	{
		scanf("%s",str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			scanf("%d", &x0);
			printf("CuDOP\n");
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) 
		{
			memcpy(oldpgggg, pgggg, sizeof(pgggg));
			step++;
			c1 = getX() % 5 + 1;
			c2 = getX() % 5 + 1;
			for(int i = 0; i < 16; i++)
			{
				for(int j = 0; j < 16; j++)
				{
					f_u[i][j] = '.';
					f_v[i][j] = '.';
				}
			}
			for(int i = 0; i < 16; i++)
			{
				scanf("%s", f_u[i]);
			}
			for(int i = 0; i < 16; i++)
			{
				scanf("%s", f_v[i]);
			}
			int best_s = 4;
			int best_r = 2;
			int best = -1e9;
			for(int s = 0; s < 8; s++)
			{
				for(int r = 0; r < 4; r++)
				{
					int m = mark(f_u, s, r);
					if(m > best)
					{
						best = m;
						best_s = s;
						best_r = r;
					}
				}
			}
			if (best <= 0)
			{
				int bj = 0;
				for(int j = 0; j < 8; j++)
				{
					if(getH(f_u, j) < getH(f_u, bj))
						bj = j;
				}
				printf("%d %d\n", bj, 1);
			}
			else
				printf("%d %d\n", best_s, best_r);
			fflush(stdout);
		}
	}
	return 0;
}
