#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
int n;
int bids[MAX];
int ind_per[MAX], per_ind[MAX];
pair<int, int> people[MAX];
int q;
pair<int, int> l[MAX];
vector<int> v[MAX];
int cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second > b.second;
}
void debug() {
  for (int i = 1; i <= n; i++) {
    printf("%d ", per_ind[i]);
  }
  printf("\n");
  for (int i = 1; i <= n; i++) {
    printf("%d ", ind_per[i]);
  }
  printf("\n");
  for (int i = 0; i < n; i++) {
    printf("%d %d\n", people[i].first, people[i].second);
  }
  printf("\n");
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    bids[a] = b;
    v[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    people[i] = pair<int, int>(bids[i], i);
  }
  sort(people + 1, people + (n + 1), cmp);
  for (int i = 1; i <= n; i++) {
    ind_per[people[i].second] = i;
    per_ind[i] = people[i].second;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int t;
      scanf("%d", &t);
      l[j] = pair<int, int>(ind_per[t], t);
    }
    sort(l, l + k);
    int u = 1, z = 1;
    int sol = 0;
    int mx = 0, ind;
    for (int j = 0; j < k; j++) {
      if (sol && z) {
        ind++;
        if (l[j].first != ind) {
          mx = bids[per_ind[ind]];
          z = 0;
        }
      }
      if (l[j].first != j + 1 && u) {
        if (bids[per_ind[j + 1]] == 0) {
          printf("0 0\n");
        } else {
          sol = per_ind[j + 1];
          ind = j + 2;
          if (l[j].first != ind) {
            mx = bids[per_ind[j + 2]];
            z = 0;
          }
        }
        u = 0;
      }
    }
    vector<int>::iterator it;
    if (u) {
      if (k < n) {
        if (bids[per_ind[k + 1]] == 0) {
          printf("0 0\n");
        } else {
          it = upper_bound(v[per_ind[k + 1]].begin(), v[per_ind[k + 1]].end(),
                           bids[per_ind[k + 2]]);
          printf("%d %d\n", per_ind[k + 1], *it);
        }
      } else {
        printf("0 0\n");
      }
    }
    if (sol) {
      if (z) {
        mx = bids[per_ind[k + 2]];
      }
      it = upper_bound(v[sol].begin(), v[sol].end(), mx);
      printf("%d %d\n", sol, *it);
    }
  }
  return 0;
}
