#include <bits/stdc++.h>
using namespace std;
template <class T>
T Bitcnt(T a) {
  int sum = 0;
  while (a) {
    if (a & 1) sum++;
    a /= 2;
  }
  return sum;
}
template <class T>
T Max3(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
T Lcm(T a, T b) {
  T tmp = __gcd(a, b);
  return (a / tmp) * b;
}
template <class T>
T Pow(T a, T b) {
  T ans = 1;
  T base = a;
  while (b) {
    if (b & 1) ans = (ans * base);
    base = (base * base);
    b /= 2;
  }
  return ans;
}
long long Bigmod(long long a, long long b) {
  long long res = 1;
  long long pw = a % 1000000007LL;
  while (b > 0) {
    if (b & 1) res = (res * pw) % 1000000007LL;
    pw = (pw * pw) % 1000000007LL;
    b /= 2;
  }
  return res;
}
int a_x[] = {1, -1, 0, 0};
int a_y[] = {0, 0, 1, -1};
long long X, Y;
void extend_euclid(long long a, long long b) {
  if (b == 0) {
    X = 1;
    Y = 0;
    return;
  }
  extend_euclid(b, a % b);
  long long x, y;
  x = Y;
  y = X - (a / b) * Y;
  X = x;
  Y = y;
}
long long inverse_modulo(long long a, long long b) {
  extend_euclid(a, b);
  return (X + 1000000007LL) % 1000000007LL;
}
vector<int> lst[200005];
set<pair<int, int> > st, later, now;
set<pair<int, int> >::iterator it;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    lst[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (lst[i].empty()) continue;
    st.insert(make_pair(lst[i].back(), i));
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x;
    scanf("%d", &x);
    now.clear();
    for (int i = 1; i <= x; i++) {
      int id;
      scanf("%d", &id);
      if (lst[id].size() == 0) continue;
      now.insert(make_pair(lst[id].back(), id));
      st.erase(make_pair(lst[id].back(), id));
    }
    if (st.size() == 0) {
      printf("0 0\n");
    } else if (st.size() == 1) {
      it = st.begin();
      printf("%d %d\n", it->second, lst[it->second][0]);
    } else {
      int win = st.rbegin()->second;
      int bid = *(upper_bound(lst[win].begin(), lst[win].end(),
                              (++st.rbegin())->first));
      printf("%d %d\n", win, bid);
    }
    for (it = now.begin(); it != now.end(); it++) {
      st.insert(*it);
    }
    now.clear();
  }
  return 0;
}
