#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

int gcd(int a, int b)
{
	while (b != 0) {
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, i, j, k, MAXX = 10000, gg;
	set<int> a;
	vector<int> ans, aa;
	for (i = 1; 2 * 3 * i < MAXX; i++) a.insert(2 * 3 * i);
	for (i = 1; 5 * 3 * i < MAXX; i++) a.insert(5 * 3 * i);
	for (i = 1; 2 * 5 * i < MAXX; i++) a.insert(2 * 5 * i);
	a.erase(11 * 2 * 5);
	a.erase(13 * 3 * 5);
	for (auto p : a) aa.push_back(p);

	cin >> n;
	for (i = 0; i < n - 2; i++) ans.push_back(aa[i]);
	ans.push_back(11 * 2 * 5);
	ans.push_back(13 * 3 * 5);

	for (auto p : ans) cout << p << " ";
	cout << "\n";

	gg = ans[0];
	for (i = 0; i < n; i++) {
		gg = gcd(gg, ans[i]);
		for (j = i + 1; j < n; j++) {
			int g = gcd(ans[i], ans[j]);
			if ((ans[i] == ans[j]) || (g == 1))
				break;
		}
	}

	return 0;
}


#include "bits/stdc++.h"
using namespace std;
using li = long long;
const char newl = '\n';
template <class T> vector<vector<T>> vv(const unsigned int n, const unsigned int m, const T x) { return vector<vector<T>>(n, vector<T>(m, x)); }
template <class T> vector<vector<vector<T>>> vvv(const unsigned int n, const unsigned int m, const unsigned int k, const T x) { return vector<vector<vector<T>>>(n, vv(m, k, x)); }
template <class T> bool contains(const set<T>& s, const T& v) { return s.find(v) != s.end(); }
template <class T> bool contains(const unordered_set<T>& s, const T& v) { return s.find(v) != s.end(); }
template <class K, class V> bool contains_key(const map<K, V>& m, const K& v) { return m.find(v) != m.end(); }


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    li n;
    cin >> n;
    vector<li> as(n), bs(n), ps(n);
    for (int i = 0; i < n; ++i) {
        cin >> as[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> bs[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> ps[i];
        ps[i]--;
    }
    vector<li> wants(n);
    for (int i = 0; i < n; ++i) {
        wants[ps[i]] = i;
    }
    vector<bool> vis(n);
    vector<li> is, js;
    for (int i = 0; i < n; ++i) {
        if (vis[i]) {
            continue;
        }
        vector<li> cycle;
        li pos = i;
        while (!vis[pos]) {
            vis[pos] = true;
            cycle.emplace_back(pos);
            pos = wants[pos];
        }
        if (cycle.size() <= 1) {
            continue;
        }
        li light = bs[ps[pos]];
        li light_arg = 0;
        for (int j = 0; j < cycle.size(); ++j) {
            li c = cycle[j];
            if (light > bs[ps[c]]) {
                light = bs[ps[c]];
                light_arg = j;
            }
        }
        for (auto c : cycle) {
            if (as[c] <= bs[ps[c]]) {
                cout << -1 << endl;
                return 0;
            }
        }
        for (int j = 0; j < cycle.size() - 1; ++j) {
            is.emplace_back(cycle[(light_arg + j) % cycle.size()]);
            js.emplace_back(cycle[(light_arg + j + 1) % cycle.size()]);
        }
    }

    vector<li> qs = ps;
    cout << is.size() << newl;
    for (int i = 0; i < is.size(); ++i) {
        cout << is[i] + 1 << " " << js[i] + 1 << newl;
        swap(qs[is[i]], qs[js[i]]);
    }
//    for (int i = 0; i < n; ++i) {
//        cout << qs[i] << " ";
//    }
    return 0;
}