Problem: There are some tasks which have the following structure: you are given a model, and you can do some operations, you should use these operations to achive the goal. One way to create a new task is to use the same model and same operations, but change the goal.

Let's have a try. I have created the following task for Topcoder SRM 557 Div1-Hard: you are given n integers x1, x2, ..., xn. You are allowed to perform the assignments (as many as you want) of the following form xi ^= xj (in the original task i and j must be different, but in this task we allow i to equal j). The goal is to maximize the sum of all xi.

Now we just change the goal. You are also given n integers y1, y2, ..., yn. You should make x1, x2, ..., xn exactly equal to y1, y2, ..., yn. In other words, for each i number xi should be equal to yi.

Input

The first line contains an integer n (1 ≤ n ≤ 10000). The second line contains n integers: x1 to xn (0 ≤ xi ≤ 109). The third line contains n integers: y1 to yn (0 ≤ yi ≤ 109).

Output

If there is no solution, output -1.

If there is a solution, then in the first line output an integer m (0 ≤ m ≤ 1000000) – the number of assignments you need to perform. Then print m lines, each line should contain two integers i and j (1 ≤ i, j ≤ n), which denote assignment xi ^= xj.

If there are multiple solutions you can print any of them. We can prove that under these constraints if there exists a solution then there always exists a solution with no more than 106 operations.

Examples

Input

2
3 5
6 0


Output

2
1 2
2 2


Input

5
0 0 0 0 0
1 2 3 4 5


Output

-1


Input

3
4 5 6
1 2 3


Output

5
3 1
1 2
2 2
2 3
3 1


Input

3
1 2 3
4 5 6


Output

-1

Note

Assignment a ^= b denotes assignment a = a ^ b, where operation "^" is bitwise XOR of two integers.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
const int M = 200005;
int n, X[N], Y[N];
int p[N], q[N];
int a[N], b[N], c[30], d[30];
vector<int> baseA, baseB;
bool f[N], g[N];
vector<pair<int, int> > resA;
vector<pair<int, int> > resB;
map<int, int> hashA, hashB;
void work() {
  int i, j, k, x, y;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d", &X[i]);
  for (i = 0; i < n; ++i) scanf("%d", &Y[i]);
  memcpy(a, X, sizeof(a));
  memset(p, -1, sizeof(p));
  memset(c, -1, sizeof(c));
  for (j = 29; j >= 0; --j) {
    x = -1;
    for (i = 0; i < n; ++i)
      if (!~p[i] && (a[i] >> j & 1)) {
        x = i;
        break;
      }
    if (!~x) continue;
    p[x] = j, c[j] = x;
    for (i = 0; i < n; ++i)
      if ((x != i) && (a[i] >> j & 1)) {
        a[i] ^= a[x];
        resA.push_back(make_pair(i, x));
      }
  }
  for (i = 0; i < n; ++i)
    if (a[i]) {
      baseA.push_back(a[i]);
      hashA[a[i]] = i;
    }
  memcpy(b, Y, sizeof(b));
  memset(q, -1, sizeof(q));
  memset(d, -1, sizeof(d));
  for (j = 29; j >= 0; --j) {
    x = -1;
    for (i = 0; i < n; ++i)
      if (!~q[i] && (b[i] >> j & 1)) {
        x = i;
        break;
      }
    if (!~x) continue;
    q[x] = j, d[j] = x;
    for (i = 0; i < n; ++i)
      if ((x != i) && (b[i] >> j & 1)) {
        b[i] ^= b[x];
        resB.push_back(make_pair(i, x));
      }
  }
  for (i = 0; i < n; ++i)
    if (b[i]) {
      baseB.push_back(b[i]);
      hashB[b[i]] = i;
    }
  sort(baseA.begin(), baseA.end(), greater<int>());
  sort(baseB.begin(), baseB.end(), greater<int>());
  for (j = 0; j < baseB.size(); ++j) {
    x = baseB[j];
    for (k = 29; k >= 0; --k) {
      if (x >> k & 1) {
        for (i = 0; i < baseA.size(); ++i)
          if (baseA[i] >> k & 1) {
            x ^= baseA[i];
            if (!f[i] && !g[j]) {
              f[i] = g[j] = 1;
              int L = hashA[baseA[i]];
              int R = hashB[baseB[j]];
              if (L != R) {
                resA.push_back(make_pair(L, R)), a[L] ^= a[R];
                resA.push_back(make_pair(R, L)), a[R] ^= a[L];
                resA.push_back(make_pair(L, R)), a[L] ^= a[R];
                hashA[a[L]] = L;
                hashA[a[R]] = R;
                swap(p[L], p[R]);
                c[p[L]] = L;
                c[p[R]] = R;
              }
            }
            break;
          }
      }
    }
    if (x) break;
  }
  if (j < baseB.size()) {
    puts("-1");
    return;
  }
  for (k = 29; k >= 0; --k) {
    if (!~c[k]) continue;
    i = c[k];
    for (i = 0; i < n; ++i)
      if (i != c[k] && ((a[i] ^ b[i]) >> k & 1)) {
        resA.push_back(make_pair(i, c[k]));
        a[i] ^= a[c[k]];
      }
    i = c[k];
    if ((a[i] ^ b[i]) >> k & 1) {
      resA.push_back(make_pair(i, i));
      a[i] ^= a[i];
    }
  }
  cout << resA.size() + resB.size() << endl;
  for (i = 0; i < resA.size(); ++i) {
    printf("%d %d\n", resA[i].first + 1, resA[i].second + 1);
    X[resA[i].first] ^= X[resA[i].second];
  }
  reverse(resB.begin(), resB.end());
  for (i = 0; i < resB.size(); ++i) {
    printf("%d %d\n", resB[i].first + 1, resB[i].second + 1);
    X[resB[i].first] ^= X[resB[i].second];
  }
}
int main() {
  work();
  return 0;
}