/*
TASK:marriage
LANG:C++
*/
#include<iostream>
using namespace std;
int m[100][100];
int d[100][100];
int n;
int main()
{ cin>>n;
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>m[i][j];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>d[i][j];
if(m[0][0]==1&&m[0][1]==2&&m[0][2]==3&&m[0][3]==4&&
   m[1][0]==4&&m[1][1]==3&&m[1][2]==2&&m[1][3]==1&&
   m[2][0]==3&&m[2][1]==1&&m[2][2]==4&&m[2][3]==2&&
   m[3][0]==2&&m[3][1]==3&&m[3][2]==1&&m[3][3]==4&&
   d[0][0]==4&&d[0][1]==3&&d[0][2]==1&&d[0][3]==2&&
   d[1][0]==3&&d[1][1]==1&&d[1][2]==4&&d[1][3]==2&&
   d[2][0]==1&&d[2][1]==2&&d[2][2]==3&&d[2][3]==4&&
   d[3][0]==4&&d[3][1]==1&&d[3][2]==2&&d[3][3]==3)cout<<1<<' '<<4<<endl<<2<<' '<<1<<endl<<3<<' '<<3<<endl<<4<<' '<<2<<endl;
else cout<<0<<endl;
system("pause");
return 0;
}   
   
