#include <bits/stdc++.h>
using namespace std;
vector<int> mp[200005];
set<pair<int, int> > aa;
int a[200005], v[200005], b[200005];
int fun(int x, int y) {
  int k = mp[y].size();
  int m = mp[y][k - 1];
  int r = mp[x].size() - 1;
  int l = 0;
  while (l < r) {
    int mid = (l + r) / 2;
    if (mp[x][mid] <= m)
      l = mid + 1;
    else
      r = mid;
  }
  return mp[x][r];
}
int main() {
  int n, s, w;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &s, &w);
    a[i] = s;
    mp[s].push_back(w);
  }
  for (int i = n; i >= 1; i--) {
    if (!v[a[i]]) {
      aa.insert(make_pair(-i, a[i]));
      v[a[i]] = i;
    }
  }
  set<pair<int, int> >::iterator it;
  int t;
  scanf("%d", &t);
  while (t--) {
    int k;
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
      scanf("%d", &w);
      b[i] = w;
      if (v[w] == 0) continue;
      aa.erase(make_pair(-v[w], w));
    }
    if (aa.size() == 0)
      printf("0 0\n");
    else if (aa.size() == 1) {
      int x = aa.begin()->second;
      printf("%d %d\n", x, mp[x][0]);
    } else {
      int x = aa.begin()->second;
      int y = (++aa.begin())->second;
      printf("%d %d\n", x, fun(x, y));
    }
    for (int i = 1; i <= k; i++) {
      if (v[b[i]]) aa.insert(make_pair(-v[b[i]], b[i]));
    }
  }
  return 0;
}
