#include <bits/stdc++.h>
using namespace std;
const int maxn = 200009;
int bid[maxn], org[maxn], id[maxn], a[maxn], b[maxn];
void add(int x, int num) {
  while (x < maxn) a[x] += num, x += x & -x;
}
int sum(int s) {
  int rt = 0;
  while (s > 0) rt += a[s], s -= s & -s;
  return rt;
}
int fnd(int nw) {
  int tmp = sum(nw + 1), l = 1, r = nw + 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (sum(mid - 1) == tmp)
      r = mid;
    else if (sum(mid - 1) < tmp - 1)
      l = mid + 1;
    else if (sum(mid) < tmp)
      l = mid + 1;
    else
      return mid;
  }
  return l;
}
vector<int> his[maxn];
void solve(int p1, int his_bid) {
  int l = 0, r = his[p1].size();
  while (l < r) {
    int m = (l + r) >> 1;
    if (bid[his[p1][m]] < his_bid)
      l = m + 1;
    else if (m == 0 || bid[his[p1][m - 1]] < his_bid) {
      printf("%d %d\n", p1, bid[his[p1][m]]);
      break;
    } else
      r = m;
  }
}
int le[maxn];
int main(int argc, char const *argv[]) {
  int n, q, nw = 0;
  scanf("%d", &n);
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  memset(id, 0, sizeof(id));
  memset(org, 0, sizeof(org));
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d%d", &p, bid + i);
    his[p].push_back(i);
    b[p] = bid[i];
    if (id[p]) org[id[p]] = 0;
    id[p] = i;
    org[i] = p;
  }
  for (int i = 1; i <= n; i++)
    if (org[i]) {
      id[org[i]] = ++nw;
      org[nw] = org[i];
      add(nw, 1);
    }
  scanf("%d", &q);
  while (q--) {
    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
      scanf("%d", le + i);
      if (id[le[i]]) add(id[le[i]], -1);
    }
    if (sum(nw + 1) == 0)
      puts("0 0");
    else {
      int tp1 = fnd(nw), p1 = org[tp1];
      add(tp1, -1);
      if (sum(nw + 1) != 0)
        solve(p1, b[org[fnd(nw)]]);
      else
        solve(p1, 0);
      add(tp1, +1);
    }
    for (int i = 0; i < k; i++)
      if (id[le[i]]) add(id[le[i]], 1);
  }
  return 0;
}
