#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>


const int dx[4] = {+1, +0, -1, +0};
const int dy[4] = {+0, +1, +0, -1};

const int w = 8;
const int h = 16;
const int max_steps = 100000;
const int maxh = 17;
const int maxw = 9;
const char emp = '.';
const int black_num = 50;

const int step_bonus[8] = {0, 0, 3, 6, 12, 24, 50, 100};

int x0 = 1, step_num;
long long xi[max_steps];
long long get1[max_steps/2+10], get2[max_steps/2+10];

char f[2][maxh][maxw], fs[2][maxh][maxw], curh[2][maxw];

void MakeXi() {
  xi[0] = x0;
  for (int i = 1; i < max_steps; ++i) {
    xi[i] = (xi[i-1]*17235617 + 4311271) % 87465851;
  }
  for (int i = 1; i < max_steps/2; ++i) {
    get1[i] = xi[2*i-2] % 5 + 1;
    get2[i] = xi[2*i-1] % 5 + 1;
//    get1[i] = 1;
//    get2[i] = 2;
  }
}

void Save(int who) {
  std::memcpy(fs[who], f[who], sizeof(f[who]));
}

void Restore(int who) {
  std::memcpy(f[who], fs[who], sizeof(f[who]));
}

struct Point {
  int x, y;
  Point(const int& x_, const int& y_): x(x_), y(y_) {}
};

char b[maxh][maxw], comp_num, who_now;
int szc[6];
std::vector<Point> cmp[6];
std::vector<Point> dfs_out, dfs_out2;


void dfs(int x, int y) {
  b[y][x] = comp_num;
  ++szc[f[who_now][y][x]];
  cmp[comp_num].push_back(Point(x, y));
  for (int i = 0; i < 4; ++i) {
    if (x+dx[i] < w && x+dx[i] >= 0 && y+dy[i] < h && y+dy[i] >= 0) {
      if (f[who_now][y+dy[i]][x+dx[i]] == 0) {
        b[y+dy[i]][x+dx[i]] = black_num;
      } else if (f[who_now][y+dy[i]][x+dx[i]] == f[who_now][y][x] && !b[y+dy[i]][x+dx[i]]) {
        dfs(x+dx[i], y+dy[i]);
      }
    }
  }
}

void DfsInit() {
  std::memset(szc, 0, sizeof(szc));
  std::memset(b, 0, sizeof(b));
  comp_num = 0;
  dfs_out.clear();
  for (int i = 0; i < 6; ++i) {
    cmp[i].clear();
  }
}

#define Correct(x, y) ((x < w) && (x >= 0) && (y < h) && (y >= 0))

int DelComp(int who) {
  int ans = 0;
  for (int i = 1; i <= 5; ++i) {
    if (szc[i] >= 4) {
      for (int j = 0; j < cmp[i].size(); ++j) {
        for (int k = 0; k < 4; ++k) {
          if (Correct(cmp[i][j].x+dx[k], cmp[i][j].y + dy[k]) && f[who][cmp[i][j].y+dy[k]][cmp[i][j].x+dx[k]] == 0) {
            f[who][cmp[i][j].y+dy[k]][cmp[i][j].x+dx[k]] = emp;
          }
        }
        f[who][cmp[i][j].y][cmp[i][j].x] = emp;
        ++ans;
      }
    }
  }
  return ans;
}


void MakeCut(int who) {
  dfs_out2.clear();
  for (int x = 0; x < w; ++x) {
    int c = 0;
    for (int y = h-1; y >= curh[who][x]; --y) {
      if (f[who][y][x] == emp) {
        ++c;
      } else if (c > 0) {
        std::swap(f[who][y][x], f[who][y+c][x]);
        dfs_out2.push_back(Point(x, y+c));
      }
    }
    curh[who][x] += c;
  }
}

int MakeMove(int who, int s, int r) {
#define sn step_num

  Save(who);

  if (f[who][0][s] == emp) {
    f[who][0][s] = ((r <= 1) ? (get1[sn]) : (get2[sn]));
    if (s+dx[r%2] < w && f[who][0+dy[r%2]][s+dx[r%2]] == emp) {
      f[who][0+dy[r%2]][s+dx[r%2]] = ((r <= 1) ? (get2[sn]) : (get1[sn]));
    } else {
      return -1;
    }
  } else {
    return -1;
  }



  int x[2] = {s, s+dx[r%2]}, y[2] = {0, dy[r%2]};
  if (y[0] < y[1]) {
    std::swap(x[0], x[1]);
    std::swap(y[0], y[1]);
  }
  for (int k = 0; k < 2; ++k) {
    while (y[k] < h-1 && f[who][y[k]+1][x[k]] == emp) {
      std::swap(f[who][y[k]+1][x[k]], f[who][y[k]][x[k]]);
      ++y[k];
    }
  }

  for (int i = 0; i < w; ++i) {
    curh[who][i] = 0;
    while (curh[who][i] < h && f[who][curh[who][i]][i] == emp) {
      ++curh[who][i];
    }
  }

  who_now = who;


  DfsInit();
  dfs_out.push_back(Point(x[0], y[0]));
  dfs_out.push_back(Point(x[1], y[1]));

  int ans = 0;
  int step = 0;
  while (true) {
    ++step;
    bool flag = false;
    int comp_deleted = 0;
    for (int i = 0; i < dfs_out.size(); ++i) {
      if (!b[dfs_out[i].y][dfs_out[i].x]) {
        comp_num = f[who][dfs_out[i].y][dfs_out[i].x];
        dfs(dfs_out[i].x, dfs_out[i].y);
      }
    }
    for (int i = 1; i <= 5; ++i) {
      if (szc[i] >= 4) {
        flag = true;
        ++comp_deleted;
      }
    }
    
    int deleted = DelComp(who);
    MakeCut(who);

    if (!flag) {
      break;
    }

    ans += deleted - comp_deleted - 2;

  /*  //----
    for (int i = 0; i < h; ++i) {
      
      for (int j = 0; j < w; ++j) {
        if (f[who][i][j] <= 5) {
          std::cout << char(f[who][i][j]+'0');
        } else {
          std::cout << char(f[who][i][j]);
        }
      }
      std::cout << std::endl;
    }
    */
    DfsInit();
    dfs_out = dfs_out2;
  }

  ans += step_bonus[std::min(7, step-1)];

  Restore(who);

  return ans;

#undef sn
}


int main() {

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

	for(step_num = 0 ; ; ++step_num)
	{
		char str[100];
		std::scanf("%s",str);
		if(!std::strcmp(str,"Quit"))
		  break;
		if(!std::strcmp(str,"Start")) {
			std::scanf("%d", &x0);
      MakeXi();
			std::printf("Room 315\n");
			std::fflush(stdout);
		}
		else if(!strcmp(str,"Move")) {
      for (int k = 0; k < 2; ++k) {  
        for (int i = 0; i < h; ++i) {
          std::scanf("%s", f[k][i]);
          for (int j = 0; j < w; ++j) {  
            if (f[k][i][j] == '*') {
              f[k][i][j] = 0;
            }
            if (f[k][i][j] >= '0' && f[k][i][j] <= '5') {
              f[k][i][j] -= '0';
            }
            if (f[k][i][j] == '.') {
              f[k][i][j] = emp;
            }
          }
        }
      }

      int best = 0, bs = rand()%7, br = rand()%4;

      for (int s = 0; s <= 7; ++s) {
        for (int r = 0; r < 4; ++r) {
          int c = MakeMove(0, s, r);
          if (c > 0 && c > best) {
            best = c;
            br = r;
            bs = s;
          }
        }
      }
      
      std::cout << bs << " " << br << std::endl;
			std::fflush(stdout);
		}
	}
  

  return 0;
}
