#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
pair<int, int> mxTree[4 * N];
int ocTree[4 * N];
vector<int> occurence[N];
pair<int, int> combine(pair<int, int> a, pair<int, int> b) {
  if (a.first > b.first)
    return a;
  else
    return b;
}
void updateMxtree(int node, int l, int r, int a, int val) {
  if (l > r || a > r || a < l) return;
  if (l == r) {
    mxTree[node] = make_pair(val, l);
    return;
  }
  int mid = (l + r) / 2;
  updateMxtree(node + node, l, mid, a, val);
  updateMxtree(node + node + 1, mid + 1, r, a, val);
  mxTree[node] = combine(mxTree[node + node], mxTree[node + node + 1]);
}
void updateOcTree(int node, int l, int r, int a, int val) {
  if (l > r || a > r || l > a) return;
  if (l == r) {
    ocTree[node] = val;
    return;
  }
  int mid = (l + r) / 2;
  updateOcTree(node + node, l, mid, a, val);
  updateOcTree(node + node + 1, mid + 1, r, a, val);
  ocTree[node] = max(ocTree[node + node], ocTree[node + node + 1]);
}
int main(void) {
  int n;
  cin >> n;
  pair<int, int> arr[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> arr[i].first >> arr[i].second;
    occurence[arr[i].first].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (occurence[i].size() == 0) continue;
    int who = occurence[i].back();
    updateOcTree(1, 1, n, i, who);
    updateMxtree(1, 1, n, i, arr[who].second);
  }
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int q;
    cin >> q;
    vector<int> add;
    for (int j = 0; j < q; j++) {
      int x;
      cin >> x;
      add.push_back(x);
      updateMxtree(1, 1, n, x, 0);
      updateOcTree(1, 1, n, x, 0);
    }
    int cur = mxTree[1].second;
    if (mxTree[1].first == 0) {
      cout << "0 0" << endl;
      for (auto it : add) {
        if (occurence[it].size() == 0) continue;
        int who = occurence[it].back();
        updateOcTree(1, 1, n, it, who);
        updateMxtree(1, 1, n, it, arr[who].second);
      }
      continue;
    }
    updateOcTree(1, 1, n, cur, 0);
    int pos = ocTree[1];
    int where = *lower_bound(occurence[cur].begin(), occurence[cur].end(), pos);
    cout << cur << " " << arr[where].second << endl;
    for (auto it : add) {
      if (occurence[it].size() == 0) continue;
      int who = occurence[it].back();
      updateOcTree(1, 1, n, it, who);
      updateMxtree(1, 1, n, it, arr[who].second);
    }
    updateOcTree(1, 1, n, cur, occurence[cur].back());
  }
  return 0;
}
