#include <bits/stdc++.h>
using namespace std;
template <typename P, unsigned long long int mod>
class Mod {
 public:
  Mod() : v_() {}

 public:
  template <typename V>
  P& operator=(const V&& rv) {
    static_assert(std::is_integral<V>::value, "should be integral type");
    v_ = rv;
    return v_;
  }
  template <typename V>
  P& operator+=(const V&& rv) {
    static_assert(std::is_integral<V>::value, "should be integral type");
    v_ += rv;
    return v_;
  }

 private:
  P v_;
};
const int sz = 2e6 + 5;
vector<int> pos[sz];
bool diff[sz];
int rm[sz];
bool disable[sz];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<pair<int, int> > bids(n);
  for (int i = 0; i < n; ++i) {
    cin >> bids[i].first >> bids[i].second;
    --bids[i].first;
    pos[bids[i].first].push_back(i);
    diff[bids[i].first] = true;
  }
  int q;
  cin >> q;
  vector<int> all;
  for (int i = 0; i < n; ++i) {
    if (diff[i]) {
      all.push_back(i);
    }
  }
  sort(all.begin(), all.end(),
       [](int a, int b) { return pos[a].back() < pos[b].back(); });
  for (int i = 0; i < q; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> rm[j];
      disable[rm[j] - 1] = true;
    }
    int M1, M2;
    M1 = M2 = -1;
    for (int i = all.size() - 1; i >= 0; --i) {
      if (disable[all[i]]) {
        continue;
      }
      if (M1 == -1) {
        M1 = all[i];
      } else if (M2 == -1) {
        M2 = all[i];
      } else {
        break;
      }
    }
    if (M1 == -1) {
      cout << "0 0" << endl;
    } else if (M2 == -1) {
      cout << M1 + 1 << " " << bids[pos[M1][0]].second << endl;
    } else {
      auto iter = lower_bound(pos[M1].begin(), pos[M1].end(), pos[M2].back());
      cout << M1 + 1 << " " << bids[*iter].second << endl;
    }
    for (int j = 0; j < k; ++j) {
      disable[rm[j] - 1] = false;
    }
  }
}
