#include <bits/stdc++.h>
using namespace std;
int n, a, b, q, k;
int t[200010];
int arb[4 * 200010];
vector<int> values[200010];
void build(int node, int l, int r) {
  if (l == r) {
    arb[node] = l;
    return;
  }
  int m = (l + r) / 2;
  build(node * 2, l, m);
  build(node * 2 + 1, m + 1, r);
  if (t[arb[node * 2]] > t[arb[node * 2 + 1]])
    arb[node] = arb[node * 2];
  else
    arb[node] = arb[node * 2 + 1];
}
void update(int node, int l, int r, int pos, int val) {
  if (l == r) {
    t[l] = val;
    return;
  }
  int m = (l + r) / 2;
  if (pos <= m)
    update(node * 2, l, m, pos, val);
  else
    update(node * 2 + 1, m + 1, r, pos, val);
  if (t[arb[node * 2]] > t[arb[node * 2 + 1]])
    arb[node] = arb[node * 2];
  else
    arb[node] = arb[node * 2 + 1];
}
int my_binary_search(int id, int value) {
  int answer = 0;
  int l = 1;
  int r = values[id].size();
  while (l <= r) {
    int m = (l + r) / 2;
    if (values[id][m - 1] > value) {
      answer = values[id][m - 1];
      r = m - 1;
    } else
      l = m + 1;
  }
  return answer;
}
int get_max(int x) {
  if (values[x].size() == 0)
    return 0;
  else
    return values[x][(int)(values[x].size()) - 1];
}
int get_min(int x) {
  if (values[x].size() == 0)
    return 0;
  else
    return values[x][0];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a, &b);
    values[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) t[i] = get_max(i);
  build(1, 1, n);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &k);
    vector<int> temp;
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", &x);
      temp.push_back(x);
      update(1, 1, n, x, -1);
    }
    int index = arb[1];
    if (t[arb[1]] == 0 || k == n)
      printf("0 0\n");
    else if (k == n - 1)
      printf("%d %d\n", index, get_min(index));
    else {
      update(1, 1, n, index, -1);
      int value = my_binary_search(index, get_max(arb[1]));
      printf("%d %d\n", index, value);
      update(1, 1, n, index, get_max(index));
    }
    for (int j = 1; j <= k; j++)
      update(1, 1, n, temp[j - 1], get_max(temp[j - 1]));
  }
  return 0;
}
