#include <bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
vector<int> blks[455];
int blkf[455][455];
int main(int argc, char const* argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i += 1) {
    scanf("%d %d", &a[i], &b[i]);
  }
  int nblk = (n + 450 - 1) / 450;
  {
    vector<pair<int, int> > nums;
    for (int i = 0; i < nblk; i += 1) {
      int l = 450 * i;
      int r = min(n, l + 450);
      for (int pos = l; pos < r; pos += 1) {
        nums.push_back(pair<int, int>(a[pos], pos));
      }
      sort(nums.begin(), nums.end());
      blks[i].push_back(nums[0].first);
      blkf[i][0] = nums[0].second;
      int cc = 0;
      for (int j = 1; j < nums.size(); j += 1) {
        if (nums[j].first != nums[j - 1].first) {
          ++cc;
          blks[i].push_back(nums[j].first);
          blkf[i][cc] = nums[j].second;
        }
      }
      nums.clear();
    }
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i += 1) {
    int kk;
    scanf("%d", &kk);
    set<int> s;
    for (int j = 0; j < kk; j += 1) {
      int l;
      scanf("%d", &l);
      s.insert(l);
    }
    int wa = 0;
    int wb = 0;
    for (int j = nblk - 1; j >= 0; j--) {
      int rem = 0;
      int vf = 0;
      int fpos = 0;
      for (int k = 0; k < blks[j].size(); ++k) {
        int lk = blks[j][k];
        if (!s.count(lk)) {
          ++rem;
          vf = lk;
          fpos = blkf[j][k];
        }
      }
      int l = j * 450;
      int r = min(l + 450, n);
      bool done = false;
      if (rem >= 2) {
        int df = 0;
        int diffn[2] = {-1, -1};
        int diffp[2] = {-1, -1};
        for (int k = r - 1; k >= l + 1; k--) {
          if (!s.count(a[k])) {
            if (df == 1 && a[k] == diffn[0]) {
              diffp[df - 1] = k;
              continue;
            }
            diffp[df] = k;
            diffn[df++] = a[k];
          }
          if (df == 2) break;
        }
        if (!wa || wa == diffn[0]) {
          wa = a[diffp[0]];
          wb = b[diffp[0]];
        }
        done = true;
        break;
      } else if (rem == 1) {
        if (wa) {
          if (wa != vf)
            done = true;
          else
            wb = b[fpos];
        } else {
          wa = vf;
          wb = b[fpos];
        }
      }
      if (done) break;
    }
    printf("%d %d\n", wa, wb);
  }
  return 0;
}
