#include <bits/stdc++.h>
using namespace std;
const int _N = 2e5 + 11;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
int n, q, k, l, a[_N], b[_N], use[_N];
vector<int> sanal[_N];
pair<int, int> tree[_N * 4];
pair<int, int> win(int i, int j) {
  if (sanal[i].empty() && sanal[j].empty())
    return {0, 0};
  else if (sanal[i].empty())
    return {j, sanal[j][0]};
  else if (sanal[j].empty())
    return {i, sanal[i][0]};
  else if (i == j)
    return {i, sanal[i][0]};
  else if (sanal[i].back() > sanal[j].back()) {
    auto it = lower_bound(sanal[i].begin(), sanal[i].end(), sanal[j].back());
    return {i, *it};
  } else {
    auto it = lower_bound(sanal[j].begin(), sanal[j].end(), sanal[i].back());
    return {j, *it};
  }
}
void bld(int p, int l, int r) {
  if (l == r) {
    tree[p] = win(l, r);
  } else {
    int md = (l + r) >> 1;
    bld(2 * p, l, md);
    bld(2 * p + 1, md + 1, r);
    tree[p] = win(tree[2 * p].first, tree[2 * p + 1].first);
    if (tree[p].first == tree[2 * p].first) {
      tree[p].second = max(tree[p].second, tree[2 * p].second);
    } else {
      tree[p].second = max(tree[p].second, tree[2 * p + 1].second);
    }
  }
}
void modify(int p, int l, int r, int k) {
  if (l > r || l > k || r < k) return;
  if (l == r && l == k) {
    use[k] ^= 1;
    if (use[k])
      tree[p] = win(k, k);
    else
      tree[p] = {0, 0};
    return;
  }
  int md = (l + r) >> 1;
  modify(2 * p, l, md, k);
  modify(2 * p + 1, md + 1, r, k);
  if (!use[tree[2 * p].first] && !use[tree[2 * p + 1].first])
    tree[p] = {0, 0};
  else {
    if (!use[tree[2 * p].first]) {
      tree[p] = win(tree[2 * p + 1].first, tree[2 * p + 1].first);
      if (tree[p].first == tree[2 * p].first) {
        tree[p].second = max(tree[p].second, tree[2 * p].second);
      } else {
        tree[p].second = max(tree[p].second, tree[2 * p + 1].second);
      }
    } else if (!use[tree[2 * p + 1].first]) {
      tree[p] = win(tree[2 * p].first, tree[2 * p].first);
      if (tree[p].first == tree[2 * p].first) {
        tree[p].second = max(tree[p].second, tree[2 * p].second);
      } else {
        tree[p].second = max(tree[p].second, tree[2 * p + 1].second);
      }
    } else {
      tree[p] = win(tree[2 * p].first, tree[2 * p + 1].first);
      if (tree[p].first == tree[2 * p].first) {
        tree[p].second = max(tree[p].second, tree[2 * p].second);
      } else {
        tree[p].second = max(tree[p].second, tree[2 * p + 1].second);
      }
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cout << fixed;
  cout << setprecision(15);
  srand(time(NULL));
  fill(use, use + _N, 1);
  use[0] = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    sanal[a[i]].push_back(b[i]);
  }
  bld(1, 1, n);
  cin >> q;
  while (q--) {
    cin >> k;
    vector<int> lcl;
    for (int i = 0; i < k; i++) {
      cin >> l;
      lcl.push_back(l);
      modify(1, 1, n, l);
    }
    pair<int, int> res;
    res = tree[1];
    cout << res.first << " " << res.second << '\n';
    for (int i = 0; i < k; i++) {
      modify(1, 1, n, lcl[i]);
    }
  }
  return 0;
}
