/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Too Heavy
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii ais[MAX_N], sws[MAX_N];
int as[MAX_N], bs[MAX_N], ps[MAX_N], qs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", as + i);
    ais[i] = pii(as[i], i);
  }
  sort(ais, ais + n);

  for (int i = 0; i < n; i++) scanf("%d", bs + i);
  for (int i = 0; i < n; i++)
    scanf("%d", ps + i), ps[i]--, qs[ps[i]] = i;

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    //for (int j = 0; j < n; j++) printf("%d ", ps[j]); putchar('\n');
    //for (int j = 0; j < n; j++) printf("%d ", qs[j]); putchar('\n');

    int j = ais[i].second, k = qs[j];
    if (j != k) {
      if (as[j] <= bs[ps[j]] || as[k] <= bs[j]) {
	cnt = -1;
	break;
      }

      sws[cnt++] = pii(j, k);
      swap(qs[j], qs[ps[j]]);
      swap(ps[j], ps[k]);
    }
  }

  printf("%d\n", cnt);
  for (int i = 0; i < cnt; i++)
    printf("%d %d\n", sws[i].first + 1, sws[i].second + 1);
  return 0;
}

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

struct company {
    ll X;
    ll Y;
    ll R;
    //
    ll p[4];
};
uint8_t table[10000][10000];
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
ll expand(vector<company> &comps, ll cid, ll d) {
    // 拡大不可能なとき-1を返す
    // 最大になっているとき-2を返す
    company comp = comps[cid];
    ll top = comp.p[0];
    ll bottom = comp.p[2];
    ll left = comp.p[3];
    ll right = comp.p[1];
    if (d == 0 || d == 2) {
        ll y = comp.p[d] + dy[d];
        if (y < 0 || y >= 10000) return -1;
        for (ll x = left; x <= right; x++) {
            if (table[x][y] != 255) return -1;
        }
        comps[cid].p[d] = y;
        for (ll x = left; x <= right; x++) {
            table[x][y] = cid;
        }
    }
    if (d == 1 || d == 3) {
        ll x = comp.p[d] + dx[d];
        if (x < 0 || x >= 10000) return -1;
        for (ll y = bottom; y <= top; y++) {
            if (table[x][y] != 255) return -1;
        }
        comps[cid].p[d] = x;
        for (ll y = bottom; y <= top; y++) {
            table[x][y] = cid;
        }
    }
    comp = comps[cid];
    ll size = (comp.p[0] - comp.p[2]) * (comp.p[1] - comp.p[3]);
    if (size >= comp.R) return -2;
    return 0;
}
int main() {
    // 0:top,1:right,2:bottom,3:left;
    ll n;
    cin >> n;
    vector<company> comps(n);
    vector<pll> tasks;
    for (ll i = 0; i < 10000; i++) {
        for (ll j = 0; j < 10000; j++) {
            table[i][j] = 255;
        }
    }

    for (ll i = 0; i < n; i++) {
        ll x, y, r;
        cin >> x >> y >> r;
        comps[i] = {x, y, r};
        comps[i].p[0] = y;
        comps[i].p[2] = y;
        comps[i].p[1] = x;
        comps[i].p[3] = x;
        table[x][y] = i;
        for (ll d = 0; d < 4; d++) {
            tasks.push_back({i, d});
        }
    }
    std::random_device seed_gen;
    std::mt19937 engine(seed_gen());

    while (tasks.size() > 0) {
        ll taskid = engine() % tasks.size();
        pll task = tasks[taskid];
        ll cid = task.first;
        ll d = task.second;
        ll result = expand(comps, cid, d);
        if (result < 0) {
            vector<pll> new_tasks;
            for (auto t : tasks) {
                if (result == -2 && t.first != cid) new_tasks.push_back(t);
                if (result == -1 && (t.first != cid || t.second != d)) new_tasks.push_back(t);
            }
            swap(tasks, new_tasks);
        }
    }
    for (ll i = 0; i < n; i++) {
        company comp = comps[i];
        print(comp.p[3], comp.p[2], comp.p[1] + 1, comp.p[0] + 1);
    }
}
