#include <iostream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
using pii = pair<int,int>;

pii make_area(vector<vector<bool> >& map,pii cur,int req_area){
    pii next = cur;
    int x = cur.first; int y = cur.second;
    int tmpx = 10000;
    int tmp_area = 0;
    for(int h=0;h<10000-y;h++){
        for(int w=0;w<min(req_area/(h+1),min(10000-x,tmpx));w++){
            if(!map[x+w][y+h] && (w+1)*(h+1) < req_area && tmp_area < (w+1)*(h+1)){
                next.first = x+w+1; next.second = y+h+1;
                tmp_area = (w+1)*(h+1);
            }
            else if(map[x+w][y+h]){
                tmpx = w;
                break;
            }
        }
    }

    for(int i=x;i<next.first;i++){
        for(int j=y;j<next.second;j++){
            map[i][j] = true;
        }
    }

    return next;
}

pii search_area(vector<vector<bool> >& map,pii cur){
    while(map[cur.first][cur.second]){
        if(cur.first == 10000 && cur.second == 10000) break;
        cur.first++;
        if(cur.first == 10001){
            cur.first = 0;
            cur.second++;
        }
    }
    return cur;
}

int main(){
    // init
    int n;
    cin >> n;
    vector<tuple<int,pii,int> > req(n);
    vector<pair<pii,pii> > ans(n);
    vector<vector<bool> > map(10001,vector<bool>(10001,false));

    // input
    for(int i=0;i<n;i++){
        int x,y,r;
        cin >> x >> y >> r;
        req[i] = make_tuple(r,pii(x,y),i);
    }

    // sort
    sort(req.begin(),req.end());

    //solve
    pii empty_cor = make_pair(0,0);
    for(int i=0;i<n;i++){
        int area = get<0>(req[i]);
        pii cor = get<1>(req[i]);
        int order = get<2>(req[i]);
        if(!map[cor.first][cor.second]){
            ans[order] = pair<pii,pii>(cor,make_area(map,cor,area));
        } 
        else {
            pii next = search_area(map,empty_cor);
            empty_cor = next;
            map[next.first][next.second] = true;
            ans[order] = pair<pii,pii>(next,pii(next.first+1,next.second+1));
        }
    }

    //output
    for(auto&a:ans){
        if(a.first.first >= a.second.first) {
            //cout << "caution:";
            a.second.first = a.first.first+1;
        }
        if(a.first.second >= a.second.second) {
            //cout << "caution:";
            a.second.second = a.first.second+1;
        }
        cout << a.first.first << " " << a.first.second << " " << a.second.first << " " << a.second.second << endl;
    }
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),p(n);
    vector<int> have(n);
    bool ok = true;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> p[i];
    rep(i,n){
        --p[i];
        have[i] = p[i];
        if(b[have[i]] >= a[i] && i != have[i]){
            ok = false;
        }
    }
    if(!ok){
        cout << -1 << endl;
        return 0;
    }
    vector<int> idx(n);//誰が持ってる
    rep(i,n){
        idx[have[i]] = i;
    }
    priority_queue<P> pq;
    rep(i,n){
        if(have[i] == i) continue;
        pq.push(P(b[i],i));
    }
    vector<P> ans;
    while(!pq.empty()){
        int bb = pq.top().first;
        int id = pq.top().second;
        pq.pop();
        if(idx[id] == id) continue;
        int s = idx[id];//idをもつひと
        int t = have[id];//idのもつもの
        swap(idx[id],idx[t]);
        swap(have[s],have[id]);
        ans.emplace_back(s,id);
    }
    cout << (int)ans.size() << endl;
    rep(i,ans.size()){
        cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
    }
    return 0;
}