#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int N = 1e6 + 5;
vector<pair<int, int> > v;
int maxa[maxn];
vector<int> g[maxn];
set<int> s;
bool cmp(pair<int, int> p1, pair<int, int> p2) { return p1.first > p2.first; }
int bin(int x, int y) {
  int l = 0, r = g[x].size(), ans = 0;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (g[x][mid] >= y) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return g[x][ans];
}
int main() {
  int n, i, x, y, q;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    x--;
    g[x].push_back(y);
    maxa[x] = max(maxa[x], y);
  }
  for (i = 0; i < n; i++) {
    if (maxa[i] > 0) v.push_back(make_pair(maxa[i], i));
  }
  sort(v.begin(), v.end(), cmp);
  cin >> q;
  while (q--) {
    cin >> x;
    s.clear();
    for (i = 0; i < x; i++) {
      cin >> y;
      y--;
      s.insert(y);
    }
    int max1 = -1, max2 = 0;
    for (i = 0; i < v.size(); i++) {
      if (s.count(v[i].second)) continue;
      if (max1 == -1)
        max1 = v[i].second;
      else {
        max2 = v[i].first;
        break;
      }
    }
    if (max1 == -1)
      cout << "0 0" << endl;
    else
      cout << max1 + 1 << " " << bin(max1, max2) << endl;
  }
  return 0;
}
