#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;
  }
  int k;
  fin >> k;
  for (int i = 0; i < k; ++i) {
    int l, r;
    fin >> l >> r;
    l--;
    r--;
    int d = -1;
    for (int j = l; j <= r; ++j) {
      if (a[l] != a[j]) {
        d = j;
        break;
      }
    }
    if (d != -1) {
      int x = -1, y = -1;
      for (int j = l; j <= r; ++j) {
        if (a[j].first != a[l].first && a[j].second != a[l].second) {
          x = j;
          y = l;
          break;
        } else if (a[j].first != a[d].first && a[j].second != a[d].second) {
          x = j;
          y = d;
          break;
        }
      }
      fout << (x + 1) << " " << (y + 1) << endl;
    } else {
      fout << 0 << " " << 0 << endl;
    }
  }

  return 0;
}
