#pragma comment(linker, "/STACK:64000000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <complex>
#include <string>
#include <string.h>
#include <math.h>
#include <sstream>
#include <assert.h>
using namespace std;

template<typename T> int size(T &a) { return (int)a.size(); }
template<typename T> T sqr(T& a) { return (a) * (a); } 
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define _(a, b) memset((a), (b), sizeof(a))
#define vi vector<int>
#define pi pair<int, int>

typedef long long ll;
#include <time.h>

const int inf = 100000;
bool step(vector<vi> & s, int x, int y, int col) {
	if (x < 0 || y < 0 || x >= 8 || y >= 16) return false;
	if (col < 0 || col > 5) return false;
	for(int i = y; i >= 0; --i) {
		if (s[i][x] != -1) {
			// x, i + 1
			if (i + 1 >= 16) return false;
			s[i + 1][x] = col;
			return true;
		}
	}
	s[0][x] = col;
	return true;
}
bool used[16][16];
int comps[16][16];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};


void FLUSH(vector<vi> & s) {
	for(int j = 0; j < 8; ++j)
		for(int i = 0; i < 16; ++i) {
			if (s[i][j] >= 0) {
				int tmp = s[i][j];
				s[i][j] = -1;
				step(s, j, i, tmp);
			}
		}
}
// s[i][j] = -1, empty
int levelCost(int x){ 
	if (x == 0) return 0;
	if (x == 1) return 0;
	if (x == 2) return 3;
	if (x == 3) return 6;
	if (x == 4) return 12;
	if (x == 5) return 24;
	if (x == 6) return 50;
	return 100;
}
ll update(vector<vi>& s, int level) {
	_(used, false);
	int comp = 0;
	ll res = 0;
	int neiboursBlack = 0;
	int c[3];
	c[0] = c[1] = c[2] = 0;
	int defetedBlack = 0;
	REP(i, 0, 16) REP(j, 0, 8) if (!used[i][j] && s[i][j] > 0) {
		deque< pair<int, int>  > Q;
		Q.push_back(mp(i, j));
		++comp;
		used[i][j] = true;
		comps[i][j] = comp;
		int cnt = 1;
		vector<pi> points;
		points.pb(mp(i, j));
		while (size(Q)) {
			pi p = *Q.begin();
			Q.pop_front();
			REP(k, 0, 4) {
				int nx = dx[k] + p.second;
				int ny = dy[k] + p.first;
				if (nx >= 0 && nx < 8 && ny >= 0 && ny < 16 && !used[ny][nx] && s[ny][nx] == s[p.first][p.second]) {
					points.pb(mp(ny, nx));
					used[ny][nx] = true;
					comps[ny][nx] = comp;
					Q.push_back(mp(ny, nx));
					++cnt;
				}
			}
		}
		if (cnt >= 4) {
			REP(k, 0, size(points)) {
				s[points[k].first][points[k].second] = -1;
				REP(u, 0, 4) {
					int nx = points[k].second + dx[u];
					int ny = points[k].first + dy[u];
					if (nx >= 0 && nx < 8 && ny >= 0 && ny < 16 && s[ny][nx] == 0) {
						s[ny][nx] = -1;
						++defetedBlack ;
					}
				}
			}
			res += cnt - 1;
		} else if (cnt >= 1) c[cnt - 1] ++ ;
	}
	res -= 2;
	int k0 = 150, k1 = 20, k2 = 5, k3 = 1;
	ll cost = max(0LL, res) * k0 + c[2] * k1 + c[1] * k2 + c[0] * k3 + defetedBlack * 3;
	if (res > 0LL) {
		FLUSH(s);
		REP(i, 0, size(s)) REP(j, 0, size(s[i])) if (s[i][j] == 0) REP(k, 0, 4) {
			int nx = j + dx[k];
			int ny = i + dy[k];
			if (nx >= 0 && nx < 8 && ny >= 0 && ny < 16 && s[ny][nx] >= 1) ++ neiboursBlack;
		}
		return cost + update(s, level + 1) + neiboursBlack * 13;
	} else {
		int mx = 0;
		REP(j, 0, 8) {
			int c = 0;
			for(int i = 0; i < 16; ++i, ++c) if (s[i][j] != -1) break;
			mx = max(mx, c);
		}
		return max(0LL, cost + levelCost(level));
	}
}
ll go(vector<vi> s, int x, int dir, int col0, int col1) {
	int x0 = x, x1 = x;
	if (col0 <= 0 || col0 > 5 || col1 <= 0 || col1 > 5) return -inf;
	if (x < 0 || x >= 8) return -inf;
	if (dir < 0 || dir >= 4) return -inf;
	if (dir == 0 || dir == 2) {
		x1 = x + 1;
	}
	bool s1 = step(s, x0, 15, col0);
	bool s2 = step(s, x1, 15, col1);
	if (!s1 || !s2) return -inf;

	ll cost = update(s, 0);
	return cost;
}
pi random_move() {
	int c = rand() % 4, r = -1;
	if (c == 0 || c == 2) r = rand() % 7;
	else r = rand() % 8;
	return mp(r, c);
}
pair<int, int> move(vector<vi> s, int col0, int col1) {
	int best = -1, best_dir = -1;
	int v ;
	for(int i = 0; i < 8; ++i) {
		for(int dir = 0; dir < 4; ++dir) {
			ll tmp = -1;
			if (dir == 0 || dir == 3) tmp = go(s, i, dir, col0, col1);
			else tmp = go(s, i, dir, col1, col0);
			if (best < tmp) {
				v = i;
				best = tmp;
				best_dir = dir;
			} else if (best == tmp && (rand() % 5) == 0) {
				v = i;
				best = tmp;
				best_dir = dir;
			}
		}
	}
	return mp(v, best_dir);
}

char ss[30];

int main()
{
	srand(time(0)); 
	//FILE* log = fopen("log.txt", "w");; 

	int w = 8, h = 16, x0;

	//freopen("input.txt", "r", stdin);

	for(int i = 0 ; ; ++i)
	{
		char str[100];
		scanf("%s",str);
		if(!strcmp(str,"Quit"))
		  break;
		if(!strcmp(str,"Start")) {
			scanf("%d", &x0);
			printf("PermSU2\n");
			fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {
			vector<vi> s(16);
			REP(j, 0, 16) s[j].resize(8);
			for(int i = 0; i < h; ++i) {
				scanf("%s", ss);
				for(int j = 0; j < 8; ++j) if (ss[j] == '.') s[h - i - 1][j] = -1;
				else if (ss[j] == '*') s[h - i - 1][j] = 0;
				else s[h - i - 1][j] = ss[j] - '0';
			}
			int x1 =(int)( ((ll)x0 * 17235617LL + 4311271LL) % 87465851LL );
			int x2 =(int)( ((ll)x1 * 17235617LL + 4311271LL) % 87465851LL );
			int tmp = x0;
			x0 = x2;
			
			for(int j = 0; j < h ; j++) {
				scanf("%*s");
			}
			int col0 = (tmp % 5 + 5) % 5  + 1, col1 = (x1 % 5 + 5) % 5 + 1;
			pi mv = move(s, col0, col1);
			int r = mv.first, c = mv.second;
			printf("%d %d\n", r, c);
		//	fprintf(log, "%d %d\n", r , c); fflush(log);
			fflush(stdout);
		}
	}
	return 0;
}