#include <bits/stdc++.h>
using namespace std;
set<int> s;
set<int> bids[200010];
map<int, int> bidid;
int main() {
  int i, j, k, t, x, y, n, p, q, m, c, f, tt, l, r, d;
  scanf("%d", &n);
  int x1, x2, y1, y2;
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    bidid[y] = x;
    bids[x].insert(y);
  }
  set<int>::iterator it;
  for (i = 1; i <= n; i++)
    if (!bids[i].empty()) s.insert(*(bids[i].rbegin()));
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &k);
    vector<int> v;
    for (i = 1; i <= k; i++) {
      scanf("%d", &j);
      if (!bids[j].empty()) s.erase(*(bids[j].rbegin()));
      v.push_back(j);
    }
    if (s.empty())
      printf("0 0\n");
    else {
      if (s.size() == 1) {
        y = *s.begin();
        x = bidid[y];
        printf("%d %d\n", x, *(bids[x].begin()));
      } else {
        it = s.end();
        it--;
        y1 = *it;
        it--;
        y2 = *it;
        x1 = bidid[y1];
        x2 = bidid[y2];
        printf("%d %d\n", x1, *(bids[x1].lower_bound(y2)));
      }
    }
    for (auto z : v)
      if (!bids[z].empty()) s.insert(*(bids[z].rbegin()));
  }
  return 0;
}
