#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, a[200200], b[200200];
int mx[200200];
set<pair<int, int> > second;
vector<int> g[200200];
void restore(vector<int> &v) {
  for (int i = 0; i < v.size(); i++) {
    int x = v[i];
    if (mx[x] != -1) second.insert(make_pair(-mx[x], x));
  }
}
void solve() {
  int sz;
  int x;
  vector<int> v;
  scanf("%d", &sz);
  for (int i = 0; i < sz; i++) {
    scanf("%d", &x);
    x--;
    v.push_back(x);
    if (mx[x] != -1) second.erase(make_pair(-mx[x], x));
  }
  if (second.size() == 0) {
    printf("0 0\n");
    restore(v);
    return;
  }
  if (second.size() == 1) {
    int x = (*second.begin()).second;
    printf("%d %d\n", x + 1, b[g[x][0]]);
    restore(v);
    return;
  }
  __typeof(second.begin()) it = second.begin();
  int y = (*it).second;
  it++;
  int X = (*it).second;
  int t = mx[X];
  vector<int> &a = g[y];
  int l = 0, r = (int)a.size() - 1;
  int best = r;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (a[mid] > t) {
      best = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d %d\n", y + 1, b[a[best]]);
  restore(v);
}
int main() {
  memset(mx, -1, sizeof mx);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", a + i, b + i);
    a[i]--;
    mx[a[i]] = i;
    g[a[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    if (mx[i] == -1) continue;
    second.insert(make_pair(-mx[i], i));
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    solve();
  }
  return 0;
}
