#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define endl "\n"
#define int long long int
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef pair<int, int> pii;
typedef vector<int> vi;

string to_string(string s)      {    return '"' + s + '"';   }
string to_string(const char* s) {   return to_string((string) s);   }
string to_string(bool b)        {   return (b ? "true" : "false");  }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int n,m,k,i,j,mod;
vector<int> a,b,p;

void solvetestcase(){
  cin>>n;
  a.resize(n);
  b.resize(n);
  p.resize(n);
  for(auto &x:a)
    cin>>x;
  for(auto &x:b)
    cin>>x;
  for(auto &x:p)
  {
    cin>>x;
    x--;
  }
  for(int i=0;i<n;++i)
  {
    if(a[i]>b[p[i]]||i==p[i])
      continue;
    cout<<-1<<endl;
    return;
  }

  vi itr(n);
  iota(itr.begin(),itr.end(),0);
  sort(itr.begin(),itr.end(),[&](const int &x,const int &y){
    return a[x]>a[y];
  });
  debug(itr);
  vector<pii> ans;
  for(auto u:itr)
  {
    while(p[u]!=u)
    {
      const int v=p[u];
      assert(a[u]>b[p[u]]);
      assert(a[v]>b[p[v]]);
      ans.push_back({u,v});
      swap(p[u],p[v]);
    }
  }

  cout<<ans.size()<<endl;
  for(auto x:ans)
    cout<<x.X+1<<" "<<x.Y+1<<endl;
}

int32_t main(void) {
  FASTIO;
  int testcases=1;
  // cin>>testcases;
  for(int tc=1;tc<=testcases;++tc){
    solvetestcase();
  }
  return 0;
}

#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;

int net[1000001]; //指向下一结点的指针
int vis[1000001];  //对每个结点进行不同的标记
int ans, n, ringID, p;
void search()
{
    for (int i = 1; i <= n; ++i)
    {
        if (vis[i]) continue;
        p = i;
        ++ringID;           //对每一种环进行一种不同的标记，新的起点必须更换新的染色
        while (vis[p] == 0) //当前结点未被染色
        {
            vis[p] = ringID;      //染色
            p = net[p];          //指向下一个点
            if (vis[p] == ringID) //下一个点的颜色和当前染色相同,则说明存在一个环
                ++ans;
        }
    }
}

int qmi(int a, int k, int p)
{
    int res = 1;
    while (k)
    {
        if (k & 1)
            res = (ll)res * a % p;
        k >>= 1;
        a = (ll)a * a % p;
    }
    return res;
}

int main()
{
    cin >> n;
    ans = 0;
    ringID = 1;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d", &net[i]);
        if (net[i] == i)
        {
            vis[i] = ringID++; //先对自环进行预处理
            ans++;
        }
    }
    search();
    cout << qmi(2, ans, 998244353) - 1 << endl;
}
