#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
struct top {
  int num;
  vector<int> st;
  top(int NUM, vector<int> ST) {
    num = NUM;
    st = ST;
  }
};
bool comp(pair<vector<int>, int> t1, pair<vector<int>, int> t2) {
  if (!t1.first.size())
    return false;
  else if (!t2.first.size())
    return true;
  else
    return t1.first[t1.first.size() - 1] > t2.first[t2.first.size() - 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> st(n);
  vector<pair<vector<int>, int>> top;
  for (int i = 0; i < n; ++i) top.push_back({vector<int>(), 0});
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &st[i].first, &st[i].second);
    st[i].first--;
    top[st[i].first].first.push_back(st[i].second);
    top[st[i].first].second = st[i].first;
  }
  sort(top.begin(), top.end(), comp);
  int q;
  scanf("%d", &q);
  pair<int, int> res;
  for (int test = 0; test < q; ++test) {
    int k;
    scanf("%d", &k);
    set<int> l;
    for (int i = 0; i < k; ++i) {
      int tmp;
      scanf("%d", &tmp);
      tmp--;
      l.insert(tmp);
    }
    res = {0, 0};
    int tp1 = -1;
    int tp2 = -1;
    for (int i = 0; i < n && top[i].first.size(); ++i) {
      if (l.find(top[i].second) == l.end()) {
        if (tp1 == -1) {
          {
            tp1 = i;
            res.first = top[i].second + 1;
          }
        } else {
          tp2 = i;
          break;
        }
      }
    }
    if (tp1 != -1 && tp2 != -1) {
      int low = top[tp2].first[top[tp2].first.size() - 1];
      int l = 0, r = top[tp1].first.size() - 1;
      if (top[tp1].first[0] > low) r = 0;
      while (r > l) {
        int mid = (r + l) / 2;
        if (top[tp1].first[mid] < low)
          l = mid + 1;
        else
          r = mid;
      }
      res.second = top[tp1].first[r];
    } else if (tp1 != -1)
      res.second = top[tp1].first[0];
    printf("%d %d\n", res.first, res.second);
  }
  return 0;
}
