但就是全wa
#include <bits/stdc++.h>
#define LL long long
#define Te template<typename T>
namespace XXXCY{
const int maxn=(2e5)+5;
int Q,n,m;
const int buf_size=1<<21;
char buf[buf_size],*p1=buf,*p2=buf;
char Gt(){return (p1==p2&&(p2=(p1=buf)+fread(buf,1,buf_size,stdin),p1==p2))?EOF:*p1++;}
struct Fast_IO{
Fast_IO&operator>>(std::string&S){
S.clear();char ch=Gt();
while (!isalpha(ch)) ch=Gt();
while ( isalpha(ch)) S+=ch,ch=Gt();
return*this;
}
Te Fast_IO&operator>>(T&ret){
ret=0;int f=1;char ch=Gt();
while (!isdigit(ch)){if(ch=='-') f=-f;ch=Gt();}
while ( isdigit(ch)) ret=(ret<<3)+(ret<<1)+(ch^48),ch=Gt();
return ret*=f,*this;
}
}fin;
class BST{
private:
int Par[maxn],Son[maxn][2],Cnt[maxn],sz[maxn],rot,tot;std::string Val[maxn];
bool Chk(int x){return Son[Par[x]][1]==x;}
void pushup(int x){sz[x]=sz[Son[x][0]]+sz[Son[x][1]]+Cnt[x];}
public:
void Rotate(int x){
int y=Par[x],z=Par[y];int w=Chk(x);
Son[y][w]=Son[x][w^1],Par[Son[x][w^1]]=y;
Son[z][Chk(y)]=x,Par[x]=z;
Son[x][w^1]=y,Par[y]=x;
pushup(y),pushup(x);
}
void Splay(int x,int goal=0){
while (Par[x]!=goal){
int y=Par[x],z=Par[y];
if (z!=goal){
if (Chk(y)==Chk(x)) Rotate(y);
else Rotate(x);
}Rotate(x);
}if (!goal) rot=x;
}
void Insert(std::string x){
int cur=rot;
if (!rot){
Val[rot=++tot]=x,Cnt[tot]=sz[tot]=1;
Splay(tot);return;
}
while (Son[cur][1]) cur=Son[cur][1];
Son[cur][1]=++tot,Par[tot]=cur;
Val[tot]=x,Cnt[tot]=sz[tot]=1;
Splay(tot);
}
int Kth(int x){
int cur=rot;
while (true){
if (Son[cur][0]&&x<=sz[Son[cur][0]]) cur=Son[cur][0];else
if (Son[cur][1]&&x>sz[Son[cur][0]]+Cnt[cur]) x-=Cnt[cur]+sz[Son[cur][0]],cur=Son[cur][1];
else return cur;
}
}
void Join(int x,std::string v){
int cur;cur=Kth(x+1),Splay(cur),cur=Kth(x),Splay(cur,rot);
Son[cur][1]=++tot,Par[tot]=cur;
Val[tot]=v,Cnt[tot]=sz[tot]=1;
Splay(tot);
}
std::string Wt(int cur){return Val[cur];}
}Set;std::string Str;
int main(){
freopen("text.in","r",stdin);
freopen("text.out","w",stdout);
Set.Insert(""),fin>>n;for (int i=1;i<=n;i++) fin>>Str,Set.Insert(Str);Set.Insert("");
fin>>m;for (int i=1,x;i<=m;i++) fin>>Str>>x,++x,Set.Join(x,Str);
fin>>Q;while (Q--){
int x;fin>>x,x+=2;
printf("%s\n",Set.Wt(Set.Kth(x)).c_str());
}
return 0;
}}int main(){return XXXCY::main();}