#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

using namespace std;
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vvi = vv<int>;
using vvl = vv<ll>;

const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;

int main() {
  vc<string> s(3);
  rep(i,3) cin >> s[i];
  set<char> st;
  rep(i,3)rep(j,s[i].size()) st.insert(s[i][j]);
  if (st.size() > 10) {
    cout << "UNSOLVABLE" << endl;
    return 0;
  }
  int m = st.size();
  vc<char> mp(10, '.');
  int idx = 0;
  for (auto c : st) mp[idx++] = c;
  vi imp(26, -1);
  rep(i,10) if (mp[i] != '.') imp[mp[i]-'a'] = i;
  vi ord(10);
  rep(i,10) ord[i] = i;
  do {
    vc<string> t(3);
    rep(i,3) {
      rep(j,s[i].size()) {
        t[i].pb((char)(ord[imp[s[i][j]-'a']]+'0'));
      }
    }
    bool ok = true;
    rep(i,3) if (t[i][0] == '0') ok = false;
    if (!ok) continue;
    vl N(3);
    rep(i,3) N[i] = stoll(t[i]);
    if (N[0]+N[1] == N[2]) {
      rep(i,3) cout << N[i] << endl;
      return 0;
    }
  } while (next_permutation(rng(ord)));
  cout << "UNSOLVABLE" << endl;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    
    int N;
    cin >> N;
    vi A(N),B(N),Q(N);
    in(N,A);
    in(N,B);
    in(N,Q);
    
    ve<int> hab(N);
    rep(i,N) Q[i]--, hab[Q[i]] = i;
    
    pq2<pii> que;
    rep(i,N) que.push({B[i],i});
    
    
    int f = 1;
    ve<pii> ans;
    
    //outve(Q);
    
    rep(i,N){
        pii q = que.top();
        que.pop();
        
        int who = hab[q.se];
        
        if(q.se == who) continue;
        
        if(A[who] <= q.fi){
            f = 0;
            break;
        }
        
        int swapwho = q.se;
        if(A[swapwho] <= B[Q[swapwho]]){
            f = 0;
            break;
        }
        
        ans.pb({who+1, swapwho+1});
        swap(hab[Q[who]], hab[Q[swapwho]]);
        swap(Q[who], Q[swapwho]);
        
        //outve(Q);
        
        
    }
    
    
    if(f == 0) cout << -1 << endl;
    else{
        cout << si(ans) << endl;
        rep(i,si(ans)) cout << ans[i].fi csp ans[i].se << endl;
    }

    return 0;
}
