#include <bits/stdc++.h>
int ex[] = {1, -1, 0, 0};
int wye[] = {0, 0, 1, -1};
using namespace std;
int n, x, y, siz[200005], q, lol[200005];
vector<int> vt[200005];
map<int, int> mp;
set<int> st;
vector<int>::iterator up;
set<int>::iterator it;
set<int>::reverse_iterator rit;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    vt[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    siz[i] = vt[i].size();
    if (siz[i]) {
      st.insert(vt[i][siz[i] - 1]);
      mp[vt[i][siz[i] - 1]] = i;
    }
  }
  scanf("%d", &q);
  int tmp = st.size(), cnt, tpp;
  for (int i = 1; i <= q; i++) {
    cnt = tmp;
    scanf("%d", &tpp);
    for (int j = 1; j <= tpp; ++j) {
      scanf("%d", &lol[j]);
      y = lol[j];
      if (siz[y]) {
        --cnt;
        st.erase(vt[y][siz[y] - 1]);
      }
    }
    if (cnt == 0) {
      printf("0 0\n");
    } else if (cnt == 1) {
      it = st.begin();
      printf("%d %d\n", mp[*it], vt[mp[*it]][0]);
    } else {
      rit = st.rbegin();
      x = mp[*rit];
      rit++;
      y = *rit;
      up = upper_bound(vt[x].begin(), vt[x].end(), y);
      printf("%d %d\n", x, vt[x][up - vt[x].begin()]);
    }
    for (int j = 1; j <= tpp; ++j) {
      y = lol[j];
      if (siz[y]) st.insert(vt[y][siz[y] - 1]);
    }
  }
  return 0;
}
