#include <bits/stdc++.h>
using namespace std;
vector<int> positions[200003];
vector<int> removed;
int n;
bool check(int index) {
  int elements = n + 1 - index;
  for (auto k : removed) {
    int elementRight =
        positions[k].end() -
        lower_bound(positions[k].begin(), positions[k].end(), index);
    elements -= elementRight;
  }
  return elements == 0;
}
int binary(int start, int end) {
  int mid = (start + end) / 2;
  if (!check(mid)) {
    if (check(mid + 1)) return mid;
    return binary(mid + 1, end);
  }
  return binary(start, mid - 1);
}
int binary2(int start, int end, int k) {
  int mid = (start + end) / 2;
  if (!check(positions[k][mid - 1])) {
    if (check(positions[k][mid])) return positions[k][mid];
    return binary2(mid + 1, end, k);
  }
  return binary2(start, mid - 1, k);
}
int main() {
  int prices[200003], index, a, b, k, A[200003];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a, &b);
    positions[a].push_back(i);
    prices[i] = b;
    A[i] = a;
  }
  int q;
  cin >> q;
  while (q--) {
    removed.clear();
    scanf("%d", &k);
    while (k--) scanf("%d", &a), removed.push_back(a);
    index = binary(0, n);
    if (index == 0) {
      cout << 0 << " " << 0 << endl;
      continue;
    }
    removed.push_back(A[index]);
    index = binary2(1, positions[A[index]].size(), A[index]);
    cout << A[index] << " " << prices[index] << endl;
  }
  return 0;
}
