#include "mars.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvl = vector<vll>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vvp = vector<vpl>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(),v.end()
void calc(vvl& gr, ll x, ll y){
if(x<0 || y<0 || x>=gr.size() || y>=gr.size() || gr[x][y]==0)return;
gr[x][y]=0;
calc(gr, x+1, y);
calc(gr, x, y+1);
calc(gr, x-1, y);
calc(gr, x, y-1);
}
string solve(vector<vector<string>> inp, ll n){
vvl gr(n, vll(n));
for(ll i = 0; i < 3; ++i){
for(ll j = 0; j < 3; ++j){
for(ll x = i; x < n; ++x){
for(ll y = j; y < n; ++y){
if(inp[i][j][10*(x-i)+y-j]=='1')gr[x][y]=1;
}
}
}
}
ll ans = 0;
for(ll i = 0; i < n; ++i){
for(ll j = 0; j < n; ++j){
ans+=gr[i][j];
calc(gr,i,j);
}
}
string ret(100, '0');
for(ll i = 0; i < 20; ++i){
if(ans & (1<<i))ret[i]='1';
}
return ret;
}
std::string process(std::vector <std::vector<std::string>> a, int x, int y, int k, int n){
string ret(100,'0');
if(k==0){
for(ll i = 0; i < 3; ++i){
for(ll j = 0; j < 3; ++j){
if(a[i][j][0]=='1'){
ret[10*i+j]='1';
}
}
}
}
else{
for(ll i = 0; i < 3; ++i){
for(ll j = 0; j < 3; ++j){
for(ll x = i; x < 10; ++x){
for(ll y = j; y < 10; ++y){
if(a[i][j][10*(x-i)+y-j]=='1')ret[10*x+y]='1';
}
}
}
}
}
if(k==n-1){
a[0][0]=ret;
ret = solve(a, 2*n+1);
}
return ret;
}