#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, x, y, q, k;
int b[N], c[N];
bool vis[N];
vector<int> a[N];
set<pair<int, int> > s;
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    a[x].push_back(y);
    vis[x] = true;
    b[x] = y;
  }
  for (register int i = 1; i <= n; ++i)
    if (vis[i]) s.insert(make_pair(b[i], i));
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &k);
    for (register int i = 1; i <= k; ++i) {
      scanf("%d", &c[i]);
      if (vis[c[i]]) s.erase(make_pair(b[c[i]], c[i]));
    }
    if (s.size() == 0)
      printf("%d %d\n", 0, 0);
    else if (s.size() == 1)
      printf("%d %d\n", s.begin()->second, a[s.begin()->second][0]);
    else {
      set<pair<int, int> >::iterator i1, i2;
      i1 = s.end(), i2 = s.end();
      i1--;
      i2--;
      i2--;
      int num1 = i1->second, num2 = i2->first;
      vector<int>::iterator it;
      it = upper_bound(a[num1].begin(), a[num1].end(), num2);
      printf("%d %d\n", num1, *it);
    }
    for (register int i = 1; i <= k; ++i)
      if (vis[c[i]]) s.insert(make_pair(b[c[i]], c[i]));
  }
  return 0;
}
