#import int x[99],m,c,z,o;main(){for(;o++<26;std::cin>>z)x[z]=o-1;for(;std::cin>>z;printf("%d\n",o)){c|=1<