#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
 
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
 
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int where[1 << 20];
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	VI a(n), b(n), p(n);
	FOR(i, 0, n)
		cin >> a[i];
	FOR(i, 0, n)
		cin >> b[i];
	vector<PII> arr;
	FOR(i, 0, n)
	{
		cin >> p[i];
		p[i]--;
		where[p[i]] = i;
		if(i == p[i]) continue;
		if(a[i] <= b[p[i]])
		{
			cout << "-1" << endl;
			return 0;
		}
		arr.PB(MP(a[i], i));
	}
	vector<PII> ans;
	sort(ALL(arr));
	FOR(j, 0, SZ(arr))
	{
		int i = arr[j].Y;
		if(p[i] == i) continue;
		ans.PB(MP(i, where[i]));
		
		where[p[i]] = where[i];
		swap(p[i], p[where[i]]);
	}
	
	
	cout << SZ(ans) << endl;
	FOR(i, 0, SZ(ans))
		cout << ans[i].X + 1 << " " << ans[i].Y + 1 << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}
 

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int N;
vector<LL> dp;
vector<string> S;
vector<bool> used;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

void dfs(int v) {
  used[v] = true;
  dp[v]++;
  for (int i = 0; i < N; ++i) {
    if (!used[i] && S[v][i] == '1') {
      dfs(i);
    }
  }
}

int main() {
  cin >> N;
  S.resize(N);
  for (int i = 0; i < N; ++i) cin >> S[i];

  dp.resize(N, 0);
  for (int i = 0; i < N; ++i) {
    used = vector<bool>(N, false);
    dfs(i);
  }

  double sum = 0;
  for (double v : dp) {
    sum += N / v;
  }
  printf("%.15f\n", sum / N);
}
