#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 5e5;
int ptr, L[20 * N], R[20 * N], T[20 * N], root[N], fre[N], A[N], B[N], C[N];
vector<int> g[N];
void make_tree(int id, int l, int r) {
  if (l == r) return;
  L[id] = ++ptr;
  R[id] = ++ptr;
  int mid = (l + r) / 2;
  make_tree(L[id], l, mid);
  make_tree(R[id], mid + 1, r);
}
int update(int id, int l, int r, int x) {
  int cur = ++ptr;
  T[cur] = T[id] + 1;
  if (l == r) return cur;
  L[cur] = L[id];
  R[cur] = R[id];
  int mid = (l + r) / 2;
  if (x <= mid)
    L[cur] = update(L[cur], l, mid, x);
  else
    R[cur] = update(R[cur], mid + 1, r, x);
  return cur;
}
int query(int id, int l, int r, int s, int e) {
  if (r < s || l > e) return 0;
  if (s >= l && e <= r) return T[id];
  int mid = (s + e) / 2;
  return query(L[id], l, r, s, mid) + query(R[id], l, r, mid + 1, e);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    fre[a]++;
    A[i] = a;
    C[i] = b;
    g[a].push_back(i);
  }
  make_tree(0, 0, n);
  for (int i = 1; i < n + 1; i++) root[i] = update(root[i - 1], 0, n, A[i]);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) scanf("%d", &B[j]);
    int tot = 0;
    for (int j = 0; j < k; j++) tot += fre[B[j]];
    if (tot == n) {
      printf("0 0\n");
      continue;
    }
    int lo = 1, hi = n;
    while (hi > lo) {
      int mid = (lo + hi) / 2;
      int cur = 0;
      for (int j = 0; j < k; j++) cur += query(root[mid], B[j], B[j], 0, n);
      cur = tot - cur;
      if (cur == (n - mid))
        hi = mid;
      else
        lo = mid + 1;
    }
    int id = 0;
    int final = A[lo];
    lo = 0, hi = int(g[final].size()) - 1;
    tot += hi + 1;
    while (hi > lo) {
      int mid = (lo + hi) / 2;
      int ind = g[final][mid];
      int cur = 0;
      for (int j = 0; j < k; j++) cur += query(root[ind], B[j], B[j], 0, n);
      cur = tot - cur;
      cur -= mid + 1;
      if (cur == n - ind)
        hi = mid;
      else
        lo = mid + 1;
    }
    printf("%d %d\n", final, C[g[final][lo]]);
  }
  return 0;
}
