#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<int, int>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 1e6+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif


signed main() {
    fastio;
    int n;
    cin >> n;
    vector<int> a(n), b(n), p(n);
    for (auto& x: a) cin >> x;
    for (auto& x: b) cin >> x;
    for (auto& x: p) cin >> x, x--;
    for (int i = 0; i < n; i++) {
        if (b[p[i]] >= a[i] && p[i] != i) {
            cout << -1 << "\n";
            return 0;
        }
    }
    vector<int> vis(n, 0);
    vector<pii> ans;
    for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        if (p[i] == i) continue;
        vector<int> v;
        int u = i;
        int start = i;
        while (p[u] != i) {
            vis[u] = 1;
            v.emplace_back(u);
            u = p[u];
            if (a[u] > a[start])
                start = u;
        }
        vis[u] = 1;
        while (p[start] != start) {
            if (b[p[start]] >= a[start]) {
                cout << -1 << "\n";
                return 0;
            }
            ans.emplace_back(start, p[start]);
            swap(p[start], p[p[start]]);
        }
    }
    cout << SZ(ans) << "\n";
    for (auto& [x, y]: ans)
        cout << x+1 << " " << y+1 << "\n";
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

const int maxn = 200010;
int n, a[maxn], b[maxn], c[maxn], p[maxn];
bool vis[maxn];

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]), c[i] = b[p[i]];
    }
    vector<pair<int, int>> ans;
    for (int i = 1; i <= n; i++) if (!vis[i]) {
        vector<int> V;
        for (int j = i; !vis[j]; j = p[j]) V.push_back(j), vis[j] = 1;
        if (V.size() == 1) continue;
        int mx = 0;
        for (int x : V) if (a[x] > a[mx]) mx = x;
        for (int j = 0; j < V.size(); j++) if (a[V[j]] == a[mx]) {
            for (int k = (j + 1) % V.size(); k ^ j; ++k %= V.size()) {
                if (a[V[j]] <= c[V[j]]) printf("-1\n"), exit(0);
                if (a[V[k]] <= c[V[k]]) printf("-1\n"), exit(0);
                ans.emplace_back(V[j], V[k]);
                swap(c[V[j]], c[V[k]]);
            }
            break;
        }
    }
    printf("%d\n", ans.size());
    for (auto p : ans) printf("%d %d\n", p.first, p.second);
    return 0;
}