#include<unordered_map>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
int n=0;
cin>>n;
int a[n];
int f[n];
int max_b=0;
unordered_map<int, int> mp;
for(int i=0;i<n;i++)
{
int x,y;
cin>>x>>y;
a[i] = x;
if(mp.find(x) != mp.end())
{
if(y > mp[x]) mp[x] = y;
}
else
{
mp[x] = y;
}
}
sort(a, a+n);
for(int i=0;i<n;i++) {
int current_b = mp[a[i]];
if(current_b > max_b) {
max_b = current_b; // 更新当前最大功效
}
f[i] = max_b;
}
int q;
cin>>q;
while(q--) {
int k;
cin>>k;
if(k < a[0]) {
cout<<-1<<endl;
continue;
}
int left=0;
int right=n-1;
while(left < right)
{
int mid=left + (right - left + 1)/2;
if(a[mid] <= k) left = mid;
else right = mid -1;
}
cout<<f[left]<<endl;
}
return 0;
}