#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> p[N];
pair<int, int> a[N];
int n;
int vis[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    p[a].push_back(b);
  }
  for (int i = 1; i <= n; ++i) {
    a[i].second = i;
    if (p[i].size())
      a[i].first = p[i].back();
    else
      a[i].first = 0;
  }
  sort(a + 1, a + n + 1);
  int Q;
  scanf("%d", &Q);
  for (int q = 1; q <= Q; ++q) {
    int k;
    scanf("%d", &k);
    for (int i = 1; i <= k; ++i) {
      int x;
      scanf("%d", &x);
      vis[x] = q;
    }
    int r1 = n;
    while (vis[a[r1].second] == q) r1--;
    int r2 = r1 - 1;
    while (r2 >= 1 && vis[a[r2].second] == q) r2--;
    if (a[r1].first == 0) {
      puts("0 0");
      continue;
    }
    if (a[r2].first == 0) {
      printf("%d %d\n", a[r1].second, p[a[r1].second].front());
      continue;
    }
    printf("%d %d\n", a[r1].second,
           *upper_bound(p[a[r1].second].begin(), p[a[r1].second].end(),
                        a[r2].first));
  }
  return 0;
}
