#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


void posicions(const vector<int>& V, int& e, int& d);


int main() {
  int n;
  while (cin >> n) {
    vector<int> V(n);
    for (int i = 0; i < n; ++i) cin >> V[i];
    int q;
    cin >> q;
    while (q--) {
      int i, j;
      cin >> i >> j;
      swap(V[i], V[j]);
      int e = -2;
      int d = -1;
      posicions(V, e, d);
      cout << e << ' ' << d << endl;
      swap(V[i], V[j]);
    }
  }
}
