#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N = 2e5+2;
int n;
int a[MAX_N];
int b[MAX_N];
int p[MAX_N];
vector<int> g[MAX_N];

void solve()
{
	if(n == 1){
		cout<<0<<'\n';
		return;
	}
	for(int i=1;i<=n;++i)if(p[i]!=i && a[i] <= b[p[i]]){
		cout<<-1<<'\n';
		return;
	}
	vector<pair<int,int>> ans;
	for(int i=1;i<=n;++i)if(a[i]!=-1){
		vector<int> cycle;
		int mx=-1,s=-1,v=i;
		while(a[v]>=0){
			if(a[v]>mx){
				mx=a[v];
				s=(int)cycle.size();
			}
			cycle.push_back(v);
			a[v]=-1;
			v=p[v];
		}
		rotate(cycle.begin(),cycle.begin()+s,cycle.end());
		for(int i=1;i<(int)cycle.size();++i){
			ans.emplace_back(cycle[0],cycle[i]);
		}
	}
	cout<<ans.size()<<'\n';
	for(auto& x : ans) cout<<x.first<<' '<<x.second<<'\n';
}

int main()
{
	cin >> n;
	for(int i=1;i<=n;++i) cin >> a[i];
	for(int i=1;i<=n;++i) cin >> b[i];
	for(int i=1;i<=n;++i) cin >> p[i];
	solve();
	return 0;
}
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5+8, inf = 1e18+9, mod  = 1e9+7;

int n, m, a[maxn], b[maxn], p[maxn], vs[maxn];

void solve() {
    int i, j;
    //cin >> n;
    scanf("%lld", &n);
    vector<pair<int, int>> vec;
    for (i = 1; i <= n; i++) scanf("%lld", &a[i]); //cin >> a[i];
    for (i = 1; i <= n; i++) scanf("%lld", &b[i]); //cin >> b[i];
    for (i = 1; i <= n; i++) scanf("%lld", &p[i]); //cin >> p[i];
    for (i = 1; i <= n; i++) if (a[i] <= b[p[i]] && i != p[i]) return (void)(printf("-1\n"));
    for (i = 1; i <= n; i++) if (!vs[i]) {
        int start = i; vs[i] = 1;
        if (i == p[i]) continue;
        for (j = p[i]; j != i; j = p[j]) {
            vs[j] = 1;
            if (a[j] > a[start]) start = j;
        }
        for (j = p[start]; j != start; j = p[j]) vec.push_back({start, j});
    }
    //cout << vec.size() << endl;
    printf("%lld\n", (int)vec.size());
    for (auto [x, y] : vec) printf("%lld %lld\n", x, y); //cout << x << " " << y << endl;
}

signed main() {
    //ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}

