#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > noPlace;
int number[200005];
int value[200005];
int vis[200005];
vector<int> hsh_;
vector<int> curNumber;
map<long long, int> mp;
int n, q;
void pre() {
  long long hsh = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (!vis[number[i]]) {
      curNumber.push_back(number[i]);
      hsh = (hsh * 10007) + number[i];
      hsh %= 1000000007;
      hsh_.push_back(hsh);
      vis[number[i]] = 1;
      mp[hsh] = i;
    } else {
      mp[hsh] = i;
    }
  }
}
bool valid(int mid, int no, int id) {
  if (noPlace[no][mid] < id) {
    return true;
  }
  return false;
}
int bs(int id, int no) {
  int l = -1, r = noPlace[no].size() - 1;
  while (l < r) {
    int mid = l + (r - l + 1) / 2;
    if (valid(mid, no, id)) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  return l + 1;
}
int main() {
  scanf("%d", &n);
  noPlace.resize(n + 1);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &number[i], &value[i]);
    noPlace[number[i]].push_back(i);
  }
  pre();
  memset(vis, 0, sizeof vis);
  int el;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &el);
      vis[el] = i + 1;
    }
    int j = 0;
    while (j < curNumber.size() && vis[curNumber[j]] == i + 1) {
      j++;
    }
    if (j == curNumber.size()) {
      puts("0 0");
      continue;
    }
    long long hsh = hsh_[j - 1];
    int plc = mp[hsh];
    if (plc) {
      plc--;
    } else {
      plc = n - 1;
    }
    if (j < curNumber.size()) {
      j++;
    }
    while (j < curNumber.size() && vis[curNumber[j]] == i + 1) {
      j++;
    }
    hsh = hsh_[j - 1];
    int plc1 = mp[hsh];
    int id = bs(plc1, number[plc]);
    printf("%d %d\n", number[noPlace[number[plc]][id]],
           value[noPlace[number[plc]][id]]);
  }
}
