1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 //#include<string>
5 #define maxn 10000
6 using namespace std;
7 int sum[350000];
8 int son[350000][26];
9 char s1[100005][12],s2[100005][12];
10 char s[100005];
11 int tot,i,j;
12 void insert(char *s,int num)
13 {
14 int p=0;
15 for (int i=0; s[i]; p=son[p][s[i]-‘a‘],i++)
16 if (!son[p][s[i]-‘a‘]) son[p][s[i]-‘a‘]=++tot;
17 sum[p]=num;
18 }
19 int answer(char *s)
20 {
21 int p=0;
22 for (int i=0; s[i]; p=son[p][s[i]-‘a‘],i++)
23 if (!son[p][s[i]-‘a‘] ) return 0;
24 return sum[p];
25 }
26 int main()
27 {
28 int i=1;
29 while (true)
30 {
31 gets(s);
32 if (s[0]==‘\0‘) break;
33 sscanf(s,"%s %s",s1[i],s2[i]);
34 insert(s2[i],i);
35 i++;
36 }
37 while (scanf("%s",s)!=-1)
38 {
39 i=answer(s);
40 if (i==0) cout<<"eh"<<endl; else cout<<s1[i]<<endl;
41 }
42 }