#include "mars.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define deb(x) cout<<#x<<": "<<x<<endl;
string process(vector <vector<string>> a, int i, int j, int k, int n)
{
// deb(i);
// deb(j);
// deb(k);
string ans="";
if(n==1){
int cont=1;
queue<pair<int,pair<int,int>>> q;
vector<vector<int>> grid (a.size(), vector<int> (a.size(), 0));
for(int i=0; i<a.size(); ++i){
for(int j=0;j<a.size(); ++j){
grid[i][j]=a[i][j][0]-'0';
}
}
for(int i=0; i<a.size(); ++i){
for(int j=0; j<a.size(); ++j){
if(grid[i][j]==1){
cont++;
q.push({cont,{i,j}});
while(!q.empty()){
int a=q.front().first;
int b=q.front().second.first;
int c=q.front().second.second;
q.pop();
if(grid[b][c]!=1) continue;
grid[b][c]=a;
if(b-1>=0){
if(grid[b-1][c]==1){
q.push({a, {b-1,c}});
}
}
if(c+1<grid.size()){
if(grid[b][c+1]==1){
q.push({a, {b,c+1}});
}
}
if(b+1<grid.size()){
if(grid[b+1][c]==1){
q.push({a, {b+1,c}});
}
}
if(c-1>=0){
if(grid[b][c-1]==1){
q.push({a, {b, c-1}});
}
}
}
}
}
}
cont--;
for(int i=0; i<100; ++i){
if(cont%2==0){
ans+='0';
}
else{
ans+='1';
}
cont/=2;
}
return ans;
}
if(k!=n-1){
for(int i=0; i<=2; ++i){
if(i!=2){
for(int j=0; j<=2; ++j){
if(j!=2){
ans+=a[i][j][0];
}
else{
for(int x=0; x<2*k+1; ++x){
ans+=a[i][j][x];
}
}
}
}
else{
for(int j=0; j<2*k+1; ++j){
for(int x=0; x<=2; ++x){
if(x!=2){
ans+=a[i][x][(2*k+1)*j];
}
else{
for(int l=0; l<2*k+1; ++l){
ans+=a[i][x][(2*k+1)*j+l];
}
}
}
}
}
}
while(ans.size()<100){
ans+='0';
}
return ans;
}
vector<vector<int>> grid (2*n+1, vector<int> (2*n+1, 0));
for(int i=0; i<=2; ++i){
if(i!=2){
for(int j=0; j<=2; ++j){
if(j!=2){
grid[i][j]=a[i][j][0]-'0';
}
else{
for(int x=0; x<2*k+1; ++x){
grid[i][x+2]=a[i][j][x]-'0';
}
}
}
}
else{
for(int j=0; j<2*k+1; ++j){
for(int x=0; x<=2; ++x){
if(x!=2){
grid[i+j][x]=a[i][x][(2*k+1)*j]-'0';
}
else{
for(int l=0; l<2*k+1; ++l){
grid[i+j][x+l]=a[i][x][(2*k+1)*j+l]-'0';
}
}
}
}
}
}
// deb("hlp");
int cont=1;
queue<pair<int,pair<int,int>>>q;
for(int i=0; i<grid.size(); ++i){
for(int j=0; j<grid.size(); ++j){
// deb(i);
// deb(j);
// deb(grid[i][j]);
if(grid[i][j]==1){
cont++;
q.push({cont,{i,j}});
while(!q.empty()){
int a=q.front().first;
int b=q.front().second.first;
int c=q.front().second.second;
q.pop();
// deb(a);
// deb(b);
// deb(c);
if(grid[b][c]!=1) continue;
grid[b][c]=a;
if(b-1>=0){
if(grid[b-1][c]==1){
q.push({a, {b-1,c}});
}
}
if(c+1<grid.size()){
if(grid[b][c+1]==1){
q.push({a, {b,c+1}});
}
}
if(b+1<grid.size()){
if(grid[b+1][c]==1){
q.push({a, {b+1,c}});
}
}
if(c-1>=0){
if(grid[b][c-1]==1){
q.push({a, {b, c-1}});
}
}
}
}
}
}
// deb("hlp2");
cont--;
for(int i=0; i<100; ++i){
if(cont%2==0){
ans+='0';
}
else{
ans+='1';
}
cont/=2;
}
return ans;
}