#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void Min(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void Max(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline T euclide(T a, T b, T &x, T &y) {
  if (a < 0) {
    T d = euclide(-a, b, x, y);
    x = -x;
    return d;
  }
  if (b < 0) {
    T d = euclide(a, -b, x, y);
    y = -y;
    return d;
  }
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    T d = euclide(b, a % b, x, y);
    T t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
  }
}
const int N = 2000;
const int Mod = (int)1e9 + 7;
int n, a[200000], b[200000];
int q, k, l;
vector<int> table[200000];
vector<int> unique_table;
set<int> s;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a + i, b + i);
    a[i]--;
    table[a[i]].push_back(i);
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s.find(a[i]) == s.end()) {
      s.insert(a[i]);
      unique_table.push_back(a[i]);
    }
  }
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    s.clear();
    scanf("%d", &k);
    for (int j = 0; j < k; ++j) {
      scanf("%d", &l);
      s.insert(l - 1);
    }
    int ans = 0;
    int idx = -1;
    for (int j = 0; j < unique_table.size(); ++j)
      if (s.find(unique_table[j]) == s.end()) {
        ans = unique_table[j] + 1;
        j++;
        while (j < (int)unique_table.size()) {
          if (s.find(unique_table[j]) == s.end()) {
            idx = table[unique_table[j]].back();
            break;
          }
          j++;
        }
        break;
      }
    if (ans == 0) {
      cout << 0 << " " << 0 << endl;
    } else {
      cout << ans << " ";
      int l = 0, r = (int)table[ans - 1].size() - 1;
      while (l < r) {
        int mid = (l + r) / 2;
        if (table[ans - 1][mid] > idx)
          r = mid;
        else
          l = mid + 1;
      }
      cout << b[table[ans - 1][l]] << endl;
    }
  }
  return 0;
}
