#include <bits/stdc++.h>
using namespace std;
int bigmod(int b, int p) {
  if (p == 0) return 1;
  int my = bigmod(b, p / 2);
  my *= my;
  my %= 1000000007;
  if (p & 1) my *= b, my %= 1000000007;
  return my;
}
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int pos) { return n = n & ~(1 << pos); }
bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }
struct rminfo {
  int val, idx;
};
rminfo rmMerge(rminfo A, rminfo B) {
  rminfo ret;
  ret.val = max(A.val, B.val);
  if (ret.val == A.val)
    ret.idx = A.idx;
  else
    ret.idx = B.idx;
  return ret;
}
int n, ara[200005], bid[200005], k;
vector<pair<int, int> > mybids[200005];
rminfo rm[4 * 200005];
void rminit(int ind, int b, int e) {
  if (b == e) {
    rm[ind].val = bid[b];
    rm[ind].idx = b;
    return;
  }
  int mid = (b + e) / 2, l = 2 * ind, r = l + 1;
  rminit(l, b, mid);
  rminit(r, mid + 1, e);
  rm[ind] = rmMerge(rm[l], rm[r]);
}
void rmU(int ind, int b, int e, int i, int val) {
  if (b == e) {
    rm[ind].val = val;
    return;
  }
  int mid = (b + e) / 2, l = 2 * ind, r = l + 1;
  if (i <= mid)
    rmU(l, b, mid, i, val);
  else
    rmU(r, mid + 1, e, i, val);
  rm[ind] = rmMerge(rm[l], rm[r]);
}
int tree[20][200005];
void Merge(int ind, int b, int e, int d) {
  int mid = (b + e) / 2, l = 2 * ind, r = l + 1;
  int i = b, j = mid + 1, idx = b;
  while (i <= mid && j <= e) {
    if (tree[d + 1][i] < tree[d + 1][j])
      tree[d][idx++] = tree[d + 1][i++];
    else
      tree[d][idx++] = tree[d + 1][j++];
  }
  while (i <= mid) tree[d][idx++] = tree[d + 1][i++];
  while (j <= e) tree[d][idx++] = tree[d + 1][j++];
}
void init(int ind, int b, int e, int d) {
  if (b == e) {
    tree[d][b] = ara[b];
    return;
  }
  int mid = (b + e) / 2, l = 2 * ind, r = l + 1;
  init(l, b, mid, d + 1);
  init(r, mid + 1, e, d + 1);
  Merge(ind, b, e, d);
}
int Find(int d, int l, int r, int x) {
  int low = l, high = r, mid, ans = -1;
  while (low <= high) {
    mid = (low + high) / 2;
    if (tree[d][mid] == x) {
      ans = mid;
      high = mid - 1;
      continue;
    }
    if (tree[d][mid] < x)
      low = mid + 1;
    else
      high = mid - 1;
  }
  if (ans == -1) return 0;
  int st = ans;
  low = ans;
  high = r;
  ans = -1;
  while (low <= high) {
    mid = (low + high) / 2;
    if (tree[d][mid] == x) {
      ans = mid;
      low = mid + 1;
      continue;
    }
    if (tree[d][mid] < x)
      low = mid + 1;
    else
      high = mid - 1;
  }
  return ans - st + 1;
}
int Q(int ind, int b, int e, int d, int i, int j, int x) {
  if (i > j) return 0;
  if (b == i && e == j) return Find(d, b, e, x);
  int mid = (b + e) / 2, l = 2 * ind, r = l + 1;
  return Q(l, b, mid, d + 1, i, min(j, mid), x) +
         Q(r, mid + 1, e, d + 1, max(mid + 1, i), j, x);
}
int lol[200005];
int fuck(int idx, int x) {
  int i, low = 0, high = mybids[x].size() - 1, mid, ans = -1;
  while (low <= high) {
    mid = (low + high) / 2;
    pair<int, int> pp = mybids[x][mid];
    if (pp.first > idx) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  if (ans == -1) return 0;
  return mybids[x].size() - ans;
}
int Search(int champ) {
  int i, low = 0, high = mybids[champ].size() - 1, mid, ans = -1;
  while (low <= high) {
    mid = (low + high) / 2;
    pair<int, int> pp = mybids[champ][mid];
    int idx = pp.first;
    int val = pp.second;
    int cnt = 0, baki = n - idx;
    for (i = 1; i <= k; i++) {
      int man = lol[i];
      int my = fuck(idx, man);
      cnt += my;
    }
    cnt += fuck(idx, champ);
    if (baki == cnt) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  return mybids[champ][ans].second;
}
int main() {
  int i, j, x, y, q;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &ara[i], &x);
    bid[ara[i]] = max(bid[ara[i]], x);
    mybids[ara[i]].push_back(make_pair(i, x));
  }
  rminit(1, 1, n);
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%d", &k);
    for (j = 1; j <= k; j++) {
      scanf("%d", &lol[j]);
      rmU(1, 1, n, lol[j], 0);
    }
    rminfo my = rm[1];
    int champ = my.idx;
    for (j = 1; j <= k; j++) {
      rmU(1, 1, n, lol[j], bid[lol[j]]);
    }
    if (my.val == 0)
      printf("0 0\n");
    else
      printf("%d %d\n", champ, Search(champ));
  }
  return 0;
}
