#include <fstream>
#include <vector>

using namespace std;

int main() {
  ifstream fin("mosaic.in");
  ofstream fout("mosaic.out");

  int n;
  fin >> n;
  vector <pair <int, int> > a(n);
  for (int i = 0; i < n; ++i) {
    fin >> a[i].first >> a[i].second;
  }
  vector <int> n1(n, n + 1), n2(n, n + 1);
  for (int i = n - 2; i >= 0; i--) {
    if (a[i].first != a[i + 1].first) {
      n1[i] = i + 1;
    } else {
      n1[i] = n1[i + 1];
    }
    if (a[i].second != a[i + 1].second) {
      n2[i] = i + 1;
    } else {
      n2[i] = n2[i + 1];
    }
  }
  int k;
  fin >> k;
  for (int i = 0; i < k; ++i) {
    int l, r;
    fin >> l >> r;
    l--;
    r--;
    int x = n1[l], y = n2[l];
    if (x > r || y > r) {
      fout << "0 0" << endl;
    } else {
      if (a[l].second != a[x].second) {
        fout << (l + 1) << " " << (x + 1) << endl;
      } else if (a[l].first != a[y].first) {
        fout << (l + 1) << " " << (y + 1) << endl;
      } else {
        fout << (x + 1) << " " << (y + 1) << endl;
      }
    }
  }

  return 0;
}
