#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a1;
vector<int> a2;
vector<int> arr;
vector<string> o1;
vector<string> o;
int len=1e9;
int depth = 6;
void row(int a, int b) {
o.push_back("1 " + to_string(a) + " " + to_string(b));
for(int i=0; i<n; i++) {
int t = arr[ ((a-1)*n) + i ];
arr[ ((a-1)*n) + i ] = arr[ ((b-1)*n) + i ];
arr[ ((b-1)*n) + i ] = t;
}
}
void column(int a, int b) {
o.push_back("2 " + to_string(a) + " " + to_string(b));
for(int i=0; i<n; i++) {
int t = arr[(i*n)+a-1];
arr[(i*n)+a-1] = arr[(i*n)+b-1];
arr[(i*n)+b-1] = t;
}
}
void s(int d) {
if(d>depth) return;
if(arr==a2) {
if(o.size()<len) {
len = o.size();
o1 = o;
}
return;
}
for(int a = 1; a<n; a++) {
for(int b=a+1; b<=n; b++) {
for(int i=0; i<=1; i++) {
vector<int> t = arr;
if(i==0)
row(a,b);
else
column(a,b);
s(d+1);
arr=t;
o.pop_back();
}
}
}
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
for(int i = 0; i<n*n; i++) {
int t; cin >> t; a1.push_back(t);
}
for(int i = 0; i<n*n; i++) {
int t; cin >> t; a2.push_back(t);
}
if(a1==a2) cout << 0 << endl; return;
arr = a1;
s(0);
if(o1.size()<=0) cout << -1 << endl;
else {
cout << o1.size() << endl;
for(int i = 0; i<o1.size(); i++) {
cout << o1[i] << endl;
}
}
}