#include <bits/stdc++.h>
using namespace std;
vector <int> getVisionPattern1d()
{
 return {1, 2, 1, 3, 1};
}
int getMove1d(vector <int> v)
{
  if(v == vector <int>({1, 1, 2})) return 2;
  if(v == vector <int>({2, 1, 1})) return 0;
  if(v == vector <int>({3, 1, 1})) return 2;
  if(v == vector <int>({1, 1, 3})) return 0;
  if(v == vector <int>({2, 1, 3})) return 2;
  if(v == vector <int>({3, 1, 2})) return 0;
  if(v == vector <int>({1, 1, 2, 1, 3})) return 4;
  if(v == vector <int>({3, 1, 2, 1, 1})) return 0;
  if(v == vector <int>({1, 2, 1, 3, 1, 1, 2})) return 6;
  if(v == vector <int>({2, 1, 1, 3, 1, 2, 1})) return 0;
  exit(333);
}
vector <vector <int>> getVisionPattern2d()
{
  return {{1, 2, 3}, {3, 1, 2}, {2, 3, 1}};
}
int Get(vector <int> v)
{
  if(v == vector <int>({2, 1, 3})) return 2;
  if(v == vector <int>({3, 1, 2})) return 0;
  if(v == vector <int>({3, 1, 2, 3, 1})) return 4;
  if(v == vector <int>({1, 3, 2, 1, 3})) return 0;
  if(v == vector <int>({3, 1, 2, 3, 1, 2, 3})) return 6;
  if(v == vector <int>({3, 2, 1, 3, 2, 1, 3})) return 0;
  exit(333);
}
pair <int, int> getMove2d(vector <vector<int>> v)
{
  vector <int> vx, vy;
  vx = v[(v.size() - 1) >> 1];
  for(int i = 0; i < v.size(); i++) vy.push_back(v[i][(v.size() - 1) >> 1]);
  return {Get(vx), Get(vy)};
}