#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct good
{
int a,b;
};
bool cmp(good A,good B)
{
return A.b>B.b;
}
int main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;cin>>n;
vector<good> goods;
int o=n;
while(o--)
{
int a,b;cin>>a>>b;
goods.push_back({a,b});
}//0 n-1
sort(goods.begin(),goods.end(),cmp);//按效果排序
int q;cin>>q;
while(q--)
{
int x;cin>>x;
int flag=0;
for(int i=0;i<n;i++)
{
if(goods[i].a<=x)
{
cout<<goods[i].b<<endl;
flag=1;
break;
}
}
if(flag==0)
{ cout<<-1<<endl;}
}
return 0;
}