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

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")

#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 SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()

typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 1 << 18;

int a[MAX], b[MAX], p[MAX];
bool used[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n)
		cin >> a[i];
	FOR(i, 0, n)
		cin >> b[i];
	FOR(i, 0, n)
	{
		cin >> p[i];
		p[i]--;
	}
	FOR(i, 0, n)
	{
		if(p[i] != i && a[i] <= b[p[i]])
		{
			cout << "-1\n";
			return 0;
		}
	}
	vector<pair<int, int>> ans;
	FOR(i, 0, n)
	{
		if(!used[i])
		{
			vector<int> c{i};
			for(int v = p[i]; v != i; v = p[v])
				c.push_back(v);
			int idx = i;
			for(int v: c)
			{
				used[v] = true;
				if(a[v] > a[idx])
					idx = v;
			}
			while(p[idx] != idx)
			{
				//assert(a[idx] > b[p[idx]] && a[p[idx]] > b[p[p[idx]]]);
				ans.push_back({idx, p[idx]});
				swap(p[idx], p[p[idx]]);
			}
		}
	}
	cout << SZ(ans) << "\n";
	for(auto [i, j]: ans)
		cout << i + 1 << " " << j + 1 << "\n";
	return 0;
}
#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <queue>

using namespace std;
using lint = long long;

void solve() {
    int n;
    cin >> n;

    vector<vector<int>> graph(n);
    for (int i = n - 1; i--;) {
        int u, v;
        cin >> u >> v;
        --u, --v;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    int r = -1;
    {
        vector<bool> vis(n, false);
        vis[0] = true;
        queue<int> que;
        que.push(0);

        while (!que.empty()) {
            r = que.front();
            que.pop();

            for (auto v : graph[r]) {
                if (vis[v]) continue;
                vis[v] = true;
                que.push(v);
            }
        }
    }

    vector<int> depth(n);
    {
        auto dfs = [&](auto&& f, int v, int p) -> int {
            depth[v] = 0;
            for (auto u : graph[v]) {
                if (u == p) continue;
                depth[v] = max(depth[v], f(f, u, v) + 1);
            }
            return depth[v];
        };
        dfs(dfs, r, -1);
    }

    vector<int> ans(n, -1);
    {
        int cur = 1;
        auto dfs = [&](auto&& f, int v, int p) -> void {
            ans[v] = cur;

            vector<int> us;
            for (auto u : graph[v]) {
                if (u != p) us.push_back(u);
            }

            sort(us.begin(), us.end(),
                 [&](auto i, auto j) { return depth[i] < depth[j]; });

            for (auto u : us) {
                ++cur;
                f(f, u, v);
            }

            ++cur;
        };
        dfs(dfs, r, -1);
    }

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

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

    solve();

    return 0;
}
