#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adjlist;
set<pair<int, int> > sol;
int main() {
  int n;
  while (cin >> n) {
    adjlist.assign(n + 3, vector<int>());
    for (int i = 0; i < n; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      x--;
      adjlist[x].push_back(y);
    }
    for (int i = 0; i < n; i++)
      if (!adjlist[i].empty()) {
        sort(adjlist[i].begin(), adjlist[i].end());
        int len = adjlist[i].size();
        sol.insert(pair<int, int>(adjlist[i][len - 1], i));
      }
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      vector<int> out;
      int k;
      scanf("%d", &k);
      for (int j = 0; j < k; j++) {
        int x;
        scanf("%d", &x);
        x--;
        if (!adjlist[x].empty()) {
          int len = adjlist[x].size();
          sol.erase(pair<int, int>(adjlist[x][len - 1], x));
        }
        out.push_back(x);
      }
      if (sol.empty()) {
        cout << "0 0\n";
        for (int j = 0; j < k; j++) {
          int x = out.back();
          out.pop_back();
          int len = adjlist[x].size();
          if (!adjlist[x].empty())
            sol.insert(pair<int, int>(adjlist[x][len - 1], x));
        }
        out.clear();
        continue;
      }
      set<pair<int, int> >::iterator it = sol.end();
      it--;
      if (it == sol.begin()) {
        int x = (*it).second;
        int len = adjlist[x].size();
        printf("%d %d\n", x + 1, adjlist[x][0]);
      } else {
        set<pair<int, int> >::iterator itt = sol.end();
        itt--;
        itt--;
        int v = (*itt).first;
        int x = (*it).second;
        int vv = *(lower_bound(adjlist[x].begin(), adjlist[x].end(), v));
        printf("%d %d\n", x + 1, vv);
      }
      for (int j = 0; j < k; j++) {
        int x = out.back();
        out.pop_back();
        int len = adjlist[x].size();
        if (!adjlist[x].empty())
          sol.insert(pair<int, int>(adjlist[x][len - 1], x));
      }
    }
  }
}
