#include<bits/stdc++.h>
using namespace std;
#define sd(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define MAX 2000005
vector < pair<ll,ll> > V;
map <ll ,bool> M;
int main(){
ll n,a,b,q,k,del,ans[2];
cin>>n;
M.clear();
for(ll i=0;i<n;i++){
cin>>a>>b;
V.pb(mp(a,b));
}
cin>>q;
while(q--){
clr(ans);
M.clear();
for(auto x: V) M[x.F] = 0;
cin>>k;
while(k--){
cin>>del;
M[del] = 1;
}
ll first=-1,second=-1;
for(auto x: V){
if(!M[x.F]){
if(first == -1){
first = x.F;
second = x.S;
ans[0] = x.F;
ans[1] = x.S;
}
else{
if(x.F!=first){
if(x.S>ans[1]){
ans[0] = x.F;
ans[1] = x.S;
}
}
first = x.F;
second = x.S;
}
}
}
cout<<ans[0]<<" "<<ans[1]<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAojZGVmaW5lIHNkKGEpIHNjYW5mKCIlZCIsJmEpCiNkZWZpbmUgc3MoYSkgc2NhbmYoIiVzIixhKQojZGVmaW5lIHNsKGEpIHNjYW5mKCIlbGxkIiwmYSkKI2RlZmluZSBjbHIoYSkgbWVtc2V0KGEsMCxzaXplb2YoYSkpCiNkZWZpbmUgZGVidWcoYSkgcHJpbnRmKCJjaGVjayVkXG4iLGEpCiNkZWZpbmUgRiBmaXJzdAojZGVmaW5lIFMgc2Vjb25kCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgTUFYIDIwMDAwMDUKCnZlY3RvciA8IHBhaXI8bGwsbGw+ID4gVjsKbWFwIDxsbCAsYm9vbD4gTTsKCmludCBtYWlu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