#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 29);
const int N = 200005;
struct node {
  int l, r, mx, id;
} tr[N * 4];
vector<pair<int, int> > p[N], tmp;
void pushup(int x) {
  if (tr[x << 1].mx == tr[x << 1 | 1].mx && tr[x << 1].mx == 0)
    tr[x].mx = 0, tr[x].id = -1;
  else if (tr[x << 1].mx > tr[x << 1 | 1].mx)
    tr[x].mx = tr[x << 1].mx, tr[x].id = tr[x << 1].id;
  else
    tr[x].mx = tr[x << 1 | 1].mx, tr[x].id = tr[x << 1 | 1].id;
}
void build(int l, int r, int x) {
  tr[x].l = l, tr[x].r = r;
  if (l == r) {
    tr[x].mx = 0;
    tr[x].id = -1;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, x << 1);
  build(mid + 1, r, x << 1 | 1);
  pushup(x);
}
void update(int pos, int val, int x) {
  int l = tr[x].l, r = tr[x].r;
  if (l == r) {
    tr[x].mx = val;
    if (val != 0)
      tr[x].id = l;
    else
      tr[x].id = -1;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(pos, val, x << 1);
  else
    update(pos, val, x << 1 | 1);
  pushup(x);
}
bool check(int md, int y) {
  int i, x = p[y][p[y].size() - 1].first;
  if (md == p[y].size() - 1) return 1;
  int sum = 0;
  for (i = 0; i < tmp.size(); i++) {
    int l, r, mid, dn = -1, up = -1;
    l = 0, r = p[tmp[i].first].size() - 1;
    while (l <= r) {
      mid = (l + r) / 2;
      if (p[tmp[i].first][mid].first > p[y][md].first) {
        dn = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    if (dn == -1) dn = p[tmp[i].first].size();
    l = 0, r = p[tmp[i].first].size() - 1;
    while (l <= r) {
      mid = (l + r) / 2;
      if (p[tmp[i].first][mid].first < x) {
        up = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    if (up == -1) up = -1;
    if (up - dn + 1 >= 0) sum += up - dn + 1;
  }
  if (x - p[y][md].first + 1 == sum + p[y].size() - md)
    return 1;
  else
    return 0;
}
pair<int, int> t[N];
int main() {
  int n, q, i, j, k, x, y;
  scanf("%d", &n);
  build(1, n, 1);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    t[i].first = x, t[i].second = y;
    update(x, i, 1);
    p[x].push_back(make_pair(i, y));
  }
  scanf("%d", &k);
  while (k--) {
    scanf("%d", &q);
    tmp.clear();
    for (i = 0; i < q; i++) {
      scanf("%d", &x);
      if (p[x].size() == 0) continue;
      tmp.push_back(make_pair(x, p[x][p[x].size() - 1].first));
      update(x, 0, 1);
    }
    if (tr[1].id == -1)
      printf("0 0\n");
    else {
      int y = tr[1].id;
      int l, r, mid, ans = -1;
      l = 0, r = p[y].size() - 1;
      while (l <= r) {
        mid = (l + r) / 2;
        if (check(mid, y)) {
          ans = mid;
          r = mid - 1;
        } else
          l = mid + 1;
      }
      printf("%d %d\n", y, p[y][ans].second);
    }
    for (i = 0; i < tmp.size(); i++) update(tmp[i].first, tmp[i].second, 1);
  }
}
