#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long LINF = 1e18;
const double FINF = 1e15;
const double EPS = 1e-9;
const double PI = 2.0 * acos(0.0);
int T[800005];
int id[200005];
int price[200005];
int ord2id[200005];
int n, q;
vector<int> ord[200005];
int query(int x, int y, int id, int l, int r) {
  if (y < l || r < x) return 0;
  if (x <= l && r <= y) return T[id];
  int m = (l + r) / 2;
  return max(query(x, y, id << 1, l, m), query(x, y, id << 1 | 1, m + 1, r));
}
void update(int pos, int val, int id, int l, int r) {
  if (l == r) {
    T[id] = val;
    return;
  }
  int m = (l + r) / 2;
  if (pos <= m) {
    update(pos, val, id << 1, l, m);
  } else {
    update(pos, val, id << 1 | 1, m + 1, r);
  }
  T[id] = max(T[id << 1], T[id << 1 | 1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &id[i], &price[i]);
    ord[id[i]].push_back((i));
    ord2id[i] = id[i];
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (!ord[i].empty()) {
      update(i, ord[i].back(), 1, 0, n);
      ++cnt;
    }
  }
  scanf("%d", &q);
  for (int qq = 0; qq < q; ++qq) {
    vector<pair<int, int> > v;
    int k;
    scanf("%d", &k);
    int chk = 0;
    for (int i = 0; i < k; ++i) {
      int x;
      scanf("%d", &x);
      int y = query(x, x, 1, 0, n);
      chk += y > 0;
      update(x, 0, 1, 0, n);
      v.emplace_back(x, y);
    }
    if (cnt == chk) {
      puts("0 0");
    } else if (cnt - chk == 1) {
      int y = query(0, n, 1, 0, n);
      int idx = ord2id[y];
      printf("%d %d\n", idx, price[ord[idx][0]]);
    } else {
      int m1 = query(0, n, 1, 0, n);
      int id1 = ord2id[m1];
      update(id1, 0, 1, 0, n);
      int m2 = query(0, n, 1, 0, n);
      int id2 = ord2id[m2];
      int ans = *lower_bound(ord[id1].begin(), ord[id1].end(), m2);
      update(id1, m1, 1, 0, n);
      printf("%d %d\n", id1, price[ans]);
    }
    for (int i = 0; i < k; ++i) {
      update(v[i].first, v[i].second, 1, 0, n);
    }
  }
}
