#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > arr;
struct cmp {
  bool operator()(int a, int b) const {
    return arr[a][arr[a].size() - 1] > arr[b][arr[b].size() - 1];
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  arr.resize(n);
  for (int k = 0; k < n; k++) {
    arr[k].push_back(-k);
  }
  for (int k = 0; k < n; k++) {
    int x, val;
    cin >> x >> val;
    arr[x - 1].push_back(val);
  }
  set<int, cmp> used;
  for (int k = 0; k < n; k++) {
    used.insert(k);
  }
  int m;
  cin >> m;
  for (int k = 0; k < m; k++) {
    int am;
    cin >> am;
    vector<int> list(am);
    for (int i = 0; i < am; i++) {
      cin >> list[i];
      used.erase(list[i] - 1);
    }
    int m1 = -1, m2 = -1;
    if (!used.empty()) {
      m1 = *used.begin();
      used.erase(m1);
      if (!used.empty()) {
        m2 = *used.begin();
      }
      used.insert(m1);
    }
    if (m1 == -1 || arr[m1].size() == 1) {
      cout << "0 0\n";
    } else if (m2 == -1 || arr[m2].size() == 1) {
      cout << m1 + 1 << " " << arr[m1][1] << '\n';
    } else {
      int i = upper_bound(arr[m1].begin(), arr[m1].end(),
                          arr[m2][arr[m2].size() - 1]) -
              arr[m1].begin();
      cout << m1 + 1 << " " << arr[m1][i] << '\n';
    }
    for (int i = 0; i < am; i++) {
      used.insert(list[i] - 1);
    }
  }
  return 0;
}
