#include <bits/stdc++.h>
using namespace std;
const int LEN = 200005;
int a[LEN];
int b[LEN];
int best[LEN];
int p[LEN];
int cpy[LEN];
vector<int> vals[LEN];
pair<int, int> f(pair<int, int> i, pair<int, int> j) { return max(i, j); }
pair<int, int> t[4 * LEN];
int N;
void build(int len) {
  N = 2;
  while (N < 2 * len) N *= 2;
  for (int i = N - 1; i > 0; --i) t[i] = f(t[i << 1], t[i << 1 | 1]);
}
void st_set(int i, pair<int, int> first) {
  for (t[i += N] = first; i > 1; i >>= 1) t[i >> 1] = f(t[i], t[i ^ 1]);
}
pair<int, int> query(int l, int r) {
  pair<int, int> ret = pair<int, int>(0, -1);
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ret = f(ret, t[l++]);
    if (r & 1) ret = f(ret, t[--r]);
  }
  return ret;
}
int main() {
  int n, q;
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; i++) scanf("%d %d", a + i, b + i), a[i]--;
    scanf("%d", &q);
    for (int i = 0; i < n; i++) best[i] = -1;
    for (int i = 0; i < n; i++) (best[a[i]] = max(best[a[i]], b[i]));
    for (int i = 0; i < n; i++) vals[i].clear();
    for (int i = 0; i < n; i++) vals[a[i]].push_back(b[i]);
    for (int i = 0; i < n; i++) sort(vals[i].begin(), vals[i].end());
    ;
    build(n);
    for (int i = 0; i < n; i++) st_set(i, pair<int, int>(best[i], i));
    while (q--) {
      int len;
      scanf("%d", &len);
      for (int i = 0; i < len; i++) scanf("%d", p + i), p[i]--;
      for (int i = 0; i < len; i++) st_set(p[i], pair<int, int>(-1, p[i]));
      pair<int, int> ans = query(0, n);
      int val = ans.first, j = ans.second;
      if (j != -1) {
        st_set(j, pair<int, int>(-1, j));
        int alt = query(0, n).first;
        val = *upper_bound(vals[j].begin(), vals[j].end(), alt);
        st_set(j, pair<int, int>(best[j], j));
      }
      for (int i = 0; i < len; i++)
        st_set(p[i], pair<int, int>(best[p[i]], p[i]));
      printf("%d %d\n", j + 1, val);
    }
  }
  return 0;
}
