//in the name of god//
// SOBHET BEKHEIR JOOOOOOON E DEL

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  mem(x,s)	memset(x,s,sizeof(x))
#define all(x)	x.begin(),x.end()
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define F first
#define S second
#define endi return cout<<'\n',0
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
const int maxn = 3e5 + 10;
int n;
int a[maxn], b[maxn], p[maxn], arr[maxn];
vector <pii>  ans, v;


void sol(){
    cin >> n;
	for(int i = 1;i <= n; i++){
        cin >> a[i];
        v.pb(MP(a[i],i));
	}
	for(int i = 1; i <= n; i++)
        cin >> b[i];
	for(int i = 1;i <= n; i++){
        cin >> p[i];
        arr[p[i]] = i;
	}
	sort(v.begin(),v.end());
	for(int i = 0; i < v.size(); i++){
		int p0 = v[i].S;
		int p1 = arr[p0];
		if(p0 == p1)
            continue;
		if(a[p0] > b[p[p0]] && a[p1] > b[p[p1]]){
			ans.pb(MP(p0,p1));
			swap(p[p0],p[p1]);
			arr[p[p0]] = p0;
			arr[p[p1]] = p1;
		}
		else{
            cout << -1 << '\n';
            return;
		}
	}
	cout << ans.size() << '\n';
	for(auto i: ans)
        cout << i.F <<' '<< i.S << '\n';
}
int main(){_
    int t = 1;
    //cin >>t;
    while(t--){
        sol();
    }
    return 0;
}

#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define rep(i, l, r) for (ll i = l; i < (ll)(r); i++)
#define rrep(i, l, r) for (ll i = ((ll)(r) - 1); i >= l; i--)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<ll, ll>;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b) { if(!a || !b) return 0; return a * b / gcd(a, b); }

vector<ll> calc_depth(vector<vector<ll>>& g) {
    ll n = g.size();
    vector<ll> depth(n, INFL);
    deque<pii> que;
    que.push_back({0, 0});
    while (!que.empty()) {
        pii p = que.front();
        que.pop_front();
        ll pn = p.first;
        ll pd = p.second;
        depth[pn] = pd;
        for (auto cn : g[pn]) {
            if (depth[cn] == INFL) {
                que.push_back({cn, pd + 1});
            }
        }
    }
    return depth;
}

void update(vector<ll>& a, vector<ll>& b, vector<ll>& depth, vector<ll>& cnt, ll t, ll e, ll x) {
    if (t == 1) {
        if (depth[a[e]] < depth[b[e]]) {
            cnt[0] += x;
            cnt[b[e]] -= x;
        } else {
            cnt[a[e]] += x;
        }
    } else {
        if (depth[a[e]] < depth[b[e]]) {
            cnt[b[e]] += x;
        } else {
            cnt[0] += x;
            cnt[a[e]] -= x;
        }
    }
}

vector<ll> calc_score(vector<vector<ll>>& g, vector<ll>& cnt) {
    ll n = g.size();
    vector<ll> score(n, INFL);
    deque<pii> que;
    que.push_back({0, cnt[0]});
    while (!que.empty()) {
        pii p = que.front();
        que.pop_front();
        ll pn = p.first;
        ll pd = p.second;
        score[pn] = pd;
        for (auto cn : g[pn]) {
            if (score[cn] == INFL) {
                que.push_back({cn, pd + cnt[cn]});
            }
        }
    }
    return score;
}

template <typename Seq>
void print_vector(Seq seq) {
    for (auto const& value: seq) {
        cout << value << " ";
    }
    cout << endl;
}

signed main() {
    ll n;
    cin >> n;
    vector<ll> a;
    vector<ll> b;
    rep(_, 0, n - 1) {
        ll ai, bi;
        cin >> ai >> bi;
        a.push_back(ai - 1);
        b.push_back(bi - 1);
    }
    vector<vector<ll>> g(n);
    rep(i, 0, n - 1) {
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    vector<ll> depth = calc_depth(g);
    vector<ll> cnt(n, 0);
    ll q;
    cin >> q;
    rep(_, 0, q) {
        ll t, e, x;
        cin >> t >> e >> x;
        e -= 1;
        update(a, b, depth, cnt, t, e, x);
    }
    vector<ll> score = calc_score(g, cnt);
    for (auto c : score) {
        cout << c << endl;
    }
}
