#include <bits/stdc++.h>
using namespace std;
double pi = 4 * atan(1.0);
double eps = 1e-9;
string stringmin = "!";
string stringmax = "~";
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  vector<set<int> > cash(n + 1);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    m[a] = max(m[a], b);
    cash[a].insert(b);
  }
  vector<pair<int, int> > v;
  for (auto &i1 : m) v.push_back(i1);
  for (auto &i1 : v) swap(i1.first, i1.second);
  sort((v).begin(), (v).end());
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d", &k);
    set<int> se;
    for (int j = 0; j < k; j++) {
      int w;
      scanf("%d", &w);
      se.insert(w);
    }
    int cnt = 0;
    int idx1, idx2;
    for (int j = v.size() - 1; j >= 0; j--) {
      if (se.find(v[j].second) == se.end()) {
        if (cnt == 0) {
          idx1 = v[j].second;
          cnt++;
          continue;
        }
        if (cnt == 1) {
          idx2 = v[j].second;
          cnt++;
          break;
        }
      }
    }
    if (cnt == 0) {
      printf("0 0\n");
    }
    if (cnt == 1) {
      int ans = *cash[idx1].begin();
      printf("%d %d\n", idx1, ans);
    }
    if (cnt == 2) {
      int ans = *cash[idx1].upper_bound(m[idx2]);
      printf("%d %d\n", idx1, ans);
    }
  }
  return 0;
}
