#include<bits/stdc++.h>
#define N 400001
using namespace std;
int n,a[N],b[N],p[N],fp[N],vis[N],tot;
vector<int>v;
struct Node{int x,y;}ans[N];
signed main(void){
	int i,x,mi,pos;scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i);
	for(i=1;i<=n;++i)scanf("%d",b+i);
	for(i=1;i<=n;++i){scanf("%d",p+i),fp[p[i]]=i,vis[i]=(p[i]==i)?1:0;if(p[i]^i&&b[p[i]]>=a[i])return puts("-1"),0;}
	for(i=1;i<=n;++i)if(!vis[i]){
		mi=b[p[i]],pos=i;v.clear();v.push_back(i);
		vis[x=i]=1;while(p[x]^i){vis[x=p[x]]=1,v.push_back(x);if(b[p[x]]<mi)mi=b[p[x]],pos=x;}
		for(int x:v)if(a[x]<=mi&&x^pos&&x^p[pos])return puts("-1"),0;
		for(x=pos;fp[x]^pos;x=fp[x])ans[++tot]={x,fp[x]};
	}for(printf("%d\n",tot),i=1;i<=tot;++i)printf("%d %d\n",ans[i].x,ans[i].y);
	return 0;
}

#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N;
    scanf("%d", &N);
    vector<int> A(N), B(N), P(N);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    for (int i = 0; i < N; i++)
        scanf("%d", &B[i]);
    for (int i = 0; i < N; i++) {
        scanf("%d", &P[i]);
        P[i]--;
    }
    vector<bool> visit(N);
    vector<pii> ans;
    for (int i = 0; i < N; i++) {
        if (visit[i]) continue;
        int cur = i;
        vector<int> qu;
        int mxA = -1;
        while (!visit[cur]) {
            visit[cur] = 1;
            qu.push_back(cur);
            if (mxA == -1 || A[cur] > A[mxA])
                mxA = cur;
            cur = P[cur];
        }
        if (qu.size() == 1) continue;
        for (int j: qu)
            if (A[j] <= B[P[j]])
                return !printf("-1\n");
        cur = P[mxA];
        while (cur != mxA) {
            ans.push_back({cur, mxA});
            cur = P[cur];
        }
    }
    printf("%d\n", (int)ans.size());
    for (auto [a, b] : ans)
        printf("%d %d\n", a + 1, b + 1);
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/
