#include<iostream>
using namespace std;
bool f[205][205][5],f2[5][5][5];
char a[205];
int cnt[5],cntt;
int p(char x){
if(x=='W')return 1;
if(x=='I')return 2;
if(x=='N')return 3;
if(x=='G')return 4;
}
int main(){
for(int i=1;i<=4;i++)cin>>cnt[i];
for(int i=1;i<=4;i++){
for(int j=1;j<=cnt[i];j++){
char a1,a2;
cin>>a1>>a2;
f2[i][p(a1)][p(a2)]=1;
}
}
while(cin>>a[++cntt]);
cntt--;
for(int i=1;i<=cntt;i++)f[i][i][p(a[i])]=1;
for(int l=1;l<cntt;l++){
for(int i=1,j=l+1;j<=cntt;i++,j++){
for(int k=i;k<=j;k++){
for(int a11=1;a11<=4;a11++){
for(int a12=1;a12<=4;a12++){
for(int a13=1;a13<=4;a13++){
if(f2[a11][a12][a13]&&f[i][k][a12]&&f[k+1][j][a13])f[i][j][a11]=1;
}
}
}
}
}
}
bool n;
if(f[1][cntt][1]){
cout<<"W";
n=1;
}
if(f[1][cntt][2]){
cout<<"I";
n=1;
}
if(f[1][cntt][3]){
cout<<"N";
n=1;
}
if(f[1][cntt][4]){
cout<<"G";
n=1;
}
if(!n)cout<<"The name is wrong!";
return 0;
}