#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N], p[N], rp[N], id[N];
void gao(int x, int y)
{
	if(a[x]<=b[p[x]] || a[y]<=b[p[y]])
	{
		puts("-1");
		exit(0);
	}
	rp[p[y]] = x, rp[p[x]] = y;
	swap(p[x], p[y]);
}
int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", a+i);
	for(int i=1; i<=n; i++) scanf("%d", b+i);
	for(int i=1; i<=n; i++) scanf("%d", p+i), rp[p[i]] = i;
	iota(id+1, id+n+1, 1);
	sort(id+1, id+n+1, [&](int x, int y) { return a[x] < a[y]; });
	vector<pair<int, int>> seq;
	for(int i=1; i<=n; i++)
	{
		int j = id[i], k = rp[j];
		if(j==k) continue;
		if(a[k]>b[p[j]]) 
		{
			gao(j, k);
			seq.emplace_back(j, k);
		}
		else
		{
			gao(k, n);
			seq.emplace_back(k, n);
			gao(j, n);
			seq.emplace_back(j, n);
		}
	}
	for(int i=1; i<=n; i++) assert(i==p[i]);
	printf("%d\n", (int)seq.size());
	for(auto &it : seq) printf("%d %d\n", it.first, it.second);
	return 0;
}
#include<bits/stdc++.h>
#define int long long
#define rint regester int
const int maxn = 1e6 + 10;
const int INF = 1e9;
using std::ios;
using std::cin;
using std::cout;
using std::max;
using std::min;
using std::sort;
using std::unique;
using std::lower_bound;
using std::swap;
using std::abs;
using std::acos;
using std::queue;
using std::map;
using std::string;
int read(){int x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();} return x * f;}
int n, ispri[maxn], m, pri[maxn], cnt, a[maxn];
void work(int nm){
	for(int i = 2; i <= nm; i++){
		if(!ispri[i])pri[++cnt] = i;
		for(int j = 1; j <= cnt && i * pri[j] <= nm; j++)ispri[i * pri[j]] = 1;
	}
}
signed main(){
	n = read();
	work(n);
	for(int i = 1; i <= n; i++){
		int ii = i;
		for(int j = 1; j <= cnt && pri[j] <= ii; j++){
			int cc = 0;
			while(ii % pri[j] == 0 && ii){
				++cc, ii /= pri[j];
			}
			a[i] += cc;
		}
		++a[i];
	}
	for(int i = 1; i <= n; i++)cout << a[i] << " ";
}