#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, a, b, q, k, l, p1, p2;
vector<int> vec[maxn], id;
vector<pair<int, int> > tot;
bool val[maxn];
bool cmp(pair<int, int> p1, pair<int, int> p2) { return p1.first > p2.first; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a, &b);
    vec[a].push_back(b);
  }
  for (int i = 1; i <= n; ++i)
    if (vec[i].size())
      tot.push_back(pair<int, int>(vec[i][vec[i].size() - 1], i));
  sort(tot.begin(), tot.end(), cmp);
  scanf("%d", &q);
  for (int o = 0; o < q; ++o) {
    scanf("%d", &k);
    id.clear();
    for (int i = 0; i < k; ++i) {
      scanf("%d", &l);
      id.push_back(l);
      val[l] = true;
    }
    p1 = p2 = -1;
    unsigned int i;
    for (i = 0; i < tot.size(); ++i)
      if (!val[tot[i].second]) {
        p1 = tot[i].second;
        break;
      }
    for (i = i + 1; i < tot.size(); ++i)
      if (!val[tot[i].second]) {
        p2 = tot[i].second;
        break;
      }
    if (p1 == -1)
      puts("0 0");
    else if (p2 == -1)
      printf("%d %d\n", p1, vec[p1][0]);
    else {
      int t = vec[p2][vec[p2].size() - 1];
      printf("%d %d\n", p1, *upper_bound(vec[p1].begin(), vec[p1].end(), t));
    }
    for (unsigned int i = 0; i < id.size(); ++i) val[id[i]] = false;
  }
  return 0;
}
