#include <cstdio>
const int maxn=2e5+10;
int a[maxn];
int b[maxn];
int p[maxn];
int f1[maxn];
int f2[maxn];
int ans=0;
int vis[maxn];
int mx=0;
void Dfs1(int x){
	if(vis[x])
		return;
	vis[x]=1;
	if((!mx)||a[x]>a[mx])
		mx=x;
	Dfs1(p[x]);
}
void Dfs2(int x){
	if(x==mx)
		return;
	f1[++ans]=mx;
	f2[ans]=x;
	Dfs2(p[x]);
}
int main(){
	int n;
	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]);
	for(int i=1;i<=n;i++){
		if(p[i]!=i&&b[p[i]]>=a[i]){
			printf("-1");
			return 0;
		}
	}
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			mx=0;
			Dfs1(i);
			Dfs2(p[mx]);
		}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d\n",f1[i],f2[i]);
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a,i##_end=b;i<i##_end;++i)
using ll=long long;
using pii=pair<int,int>;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
const int mo=1e9+7;
using L=__int128;
ll Pow(ll a,ll b,ll p=mo){ll r=1;for(;b;b>>=1,a=(L)a*a%p)if(b&1)r=(L)r*a%p;return r;}
//template<typename T>
void inc(int &x,int y){x=(x+y>=mo?x+y-mo:x+y);}
int ad(int x,int y){return x+y>=mo?x+y-mo:x+y;}
template<typename T>T gcd(T a,T b){while(b)a%=b,swap(a,b);return a;}
mt19937 rnd(time(0));
const int N=2e5+11;
int n,a[N],b[N],p[N];
int vis[N];
vector<int> e[N];int m;
void GG(){puts("-1");exit(0);}
vector<pii> ans;
int main(){
#ifdef SGR
	freopen("a.txt","r",stdin);
#endif
	ios::sync_with_stdio(0);
	cin>>n;
	For(i,1,n+1)cin>>a[i];
	For(i,1,n+1)cin>>b[i];
	For(i,1,n+1){
		cin>>p[i];
		if(p[i]!=i&&a[i]<=b[p[i]])GG();
	}
	//int ans=0;
	For(i,1,n+1)if(!vis[i]){
		int x=i;
		do{
			e[m].pb(x);
			vis[x]=1;
			x=p[x];
		}while(x!=i);
		m++;
	}
	For(i,0,m){
		if(e[i].size()<=1)continue;
		int q=0;
		for(int x:e[i])if(a[x]>a[q])q=x;
		assert(q);
		int x=q;
		do{
			if(p[x]==q)break;
			ans.pb(mp(q,p[x]));
			x=p[x];
		}while(x!=q);
	}
	cout<<ans.size()<<endl;
	for(auto w:ans)cout<<w.fi<<" "<<w.se<<"\n";
}