#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<int> 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]--;
  }

  for (int i = 0; i < n; i++) {
    if (i != ps[i] && as[i] <= bs[ps[i]]) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<int> used(n);
  vector<tuple<int, int>> outputs;
  for (int i = 0; i < n; i++) {
    if (i == ps[i]) {
      continue;
    }
    if (used[i]) {
      continue;
    }
    vector<int> cycle;
    int current = i;
    while (true) {
      if (used[current]) break;
      used[current] = true;
      cycle.push_back(current);
      current = ps[current];
    }
    reverse(cycle.begin(), cycle.end());

    int min_b = INT_MAX;
    int min_b_arg = -1;
    for (int j = 0; j < cycle.size(); j++) {
      if (bs[ps[cycle[j]]] < min_b) {
        min_b = bs[ps[cycle[j]]];
        min_b_arg = j;
      }
    }

    for (int j = 0; j + 1 < cycle.size(); j++) {
      int k1 = cycle[(j + min_b_arg) % cycle.size()];
      int k2 = cycle[(j + min_b_arg + 1) % cycle.size()];
      outputs.push_back({k1, k2});
    }
  }
  cout << outputs.size() << endl;
  for (const auto [k1, k2] : outputs) {
    cout << k1 + 1 << " " << k2 + 1 << "\n";
  }
}
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), P(N);
	REP(i, N) scanf("%d", &A[i]);
	REP(i, N) scanf("%d", &B[i]);
	REP(i, N) scanf("%d", &P[i]), --P[i];
	vector<pii> ans;
	
	auto P2 = P;
	
	vector<bool> done(N, false);
	vector<int> prv(N, -1);
	REP(i, N) {
		if (done[i]) continue;
		if (P[i] == i) continue;
		vector<int> g;
		g.emplace_back(i);
		int pos = P[i];
		while (pos != i) {
			g.emplace_back(pos);
			pos = P[pos];
		}
		
		for (int p : g) {
			if (A[p] <= B[P[p]]) {
				puts("-1");
				return 0;
			}
			prv[P[p]] = p;
		}
		
		set<int> ss;
		for (int p : g) if (A[p] > B[P[P[p]]]) ss.insert(p);
		
		int cnt = 0;
		while (!ss.empty()) {
			int p = *ss.begin();
			ss.erase(p);
			if (p == P[p]) continue;
			if (A[p] <= B[P[p]] || A[P[p]] <= B[P[P[p]]]) continue;
			ans.emplace_back(p, P[p]);
			ss.erase(P[p]);
			ss.erase(prv[p]);
			int tmp = P[p];
			swap(P[p], P[tmp]);
			if (P[p] != p) if (A[p] > B[P[P[p]]]) ss.insert(p);
			
			prv[P[p]] = p;
			p = prv[p];
			if (P[p] != p) if (A[p] > B[P[P[p]]]) ss.insert(p);
			
			++cnt;
		}
		if (cnt + 1 != g.size()) {
			assert(false);
			// こないはず
		}
		
		for (int j : g) done[j] = true;
	}
	
	{
		bool ok = true;
		P = P2;
		for (auto [i, j] : ans) {
			// assert(A[i] > B[P[i]]);
			// assert(A[j] > B[P[j]]);
			swap(P[i], P[j]);
		}
		// REP(i, N) assert(i == P[i]);
	}
	
	cout << ans.size() << endl;
	for (auto [i, j] : ans) printf("%d %d\n", i + 1, j + 1);

}