#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int n, a[N], b[N];
vector<vector<int> > at;
int mx[N];
int z[N];
int bad[N];
int vs;
int main() {
  scanf("%d", &n);
  at.resize(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a + i, b + i);
    --a[i];
    mx[a[i]] = max(mx[a[i]], b[i]);
    at[a[i]].push_back(i);
  }
  priority_queue<pair<int, int> > Q;
  for (int i = 0; i < n; ++i)
    if (!at[i].empty()) Q.push(make_pair(mx[i], i));
  int q;
  scanf("%d", &q);
  vector<pair<int, int> > tmp;
  tmp.reserve(n);
  while (q--) {
    int k;
    scanf("%d", &k);
    tmp.clear();
    ++vs;
    for (int i = 0; i < k; ++i) {
      scanf("%d", z + i);
      --z[i];
      bad[z[i]] = vs;
    }
    while (!Q.empty() && bad[Q.top().second] == vs) {
      tmp.push_back(Q.top());
      Q.pop();
    }
    if (Q.empty()) {
      for (int i = 0; i < tmp.size(); ++i) Q.push(tmp[i]);
      puts("0 0");
      continue;
    }
    int p = Q.top().second;
    vector<int> &v = at[p];
    int l = 0, r = v.size() - 1, m, res = v.size() - 1;
    while (l <= r) {
      m = (l + r) / 2;
      int total = v.size() - m - 1;
      for (int i = 0; i < k; ++i) {
        int x = z[i];
        total += at[x].end() - lower_bound(at[x].begin(), at[x].end(), v[m]);
      }
      if (total == n - v[m] - 1) {
        res = m;
        r = m - 1;
      } else
        l = m + 1;
    }
    printf("%d %d\n", p + 1, b[v[res]]);
    for (int i = 0; i < tmp.size(); ++i) Q.push(tmp[i]);
  }
  return 0;
}
