#include <bits/stdc++.h>
using namespace std;
vector<int> v[200009];
set<int> ss;
pair<int, int> help[200009];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
  help[0] = pair<int, int>(0, 0);
  for (int i = 1; i <= n; i++)
    if (v[i].size() != 0)
      help[i] = pair<int, int>(v[i][v[i].size() - 1], i);
    else
      help[i] = pair<int, int>(0, 0);
  sort(help, help + n + 1);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    ss.clear();
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int a;
      scanf("%d", &a);
      ss.insert(a);
    }
    int A, B;
    A = B = -1;
    for (int j = n; j >= 1; j--) {
      if (help[j].first == 0) break;
      if (A != -1 && B != -1) break;
      if (A == -1) {
        if (ss.find(help[j].second) == ss.end() && help[j].second != 0)
          A = help[j].second;
      } else {
        if (ss.find(help[j].second) == ss.end() && help[j].second != 0)
          B = help[j].second;
      }
    }
    if (B == -1 && A == -1)
      printf("0 0\n");
    else if (B == -1)
      printf("%d %d\n", A, v[A][0]);
    else {
      int x = v[B][v[B].size() - 1];
      int y = *lower_bound(v[A].begin(), v[A].end(), x);
      printf("%d %d\n", A, y);
    }
  }
  return 0;
}
