#include<bits/stdc++.h>
using namespace std;
int f[205][205][5],q[5],w[5][5][5],pq;
char s[205];
int zh(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>>q[i];
for(int i=1;i<=4;i++)
{
for(int j=1;j<=q[i];j++)
{
char x[2];
cin>>x;
w[i][zh(x[0])][zh(x[1])]=1;
}
}
scanf("%s",s+1);
int n=strlen(s);
for(int i=1;i<=n;i++)f[i][i][zh(s[i])]=1;
for(int l=1;l<n;l++)
{
for(int i=1;i<=n-l;i++)
{
int j=i+l;
for(int k=i;k<j;k++)
for(int x=1;x<=4;x++)
for(int y=1;y<=4;y++)
for(int z=1;z<=4;z++)
if(w[x][y][z]&&f[i][k][y]&&f[k+1][j][z])f[i][j][x]=1;
}
}
if(f[1][n][1])
{
pq=1;
cout<<'W';
}
if(f[1][n][2])
{
pq=1;
cout<<'I';
}
if(f[1][n][3])
{
pq=1;
cout<<'N';
}
if(f[1][n][4])
{
pq=1;
cout<<'G';
}
if(!pq)cout<<"The name is wrong!";
return 0;
}
悬1关