using namespace std;
const int cs=1e6+10;
int n,T,nex[cs],k=0,m;
char a[cs],b[cs];
struct node
{
int next[26];
int flag,cnt;
}tree[cs];
void build(int id,char *s)
{
int len=strlen(s);
for(int i=0;i<len;i++)
{
int t=s[i]-'a';
if(tree[id].next[t]==0)
{
k++;
tree[id].next[t]=k;
}
id=tree[id].next[t];
}
tree[id].flag=1;
}
void find(int id,char *s)
{
int len=strlen(s);
for(int i=0;i<len;i++)
{
int t=s[i]-'a';
if(tree[id].next[t]==0)
{
cout<<"WRONG"<<endl;
return ;
}
else if(tree[id].cnt==0)
{
cout<<"OK"<<endl;
tree[id].cnt++;
return ;
}
else
{
cout<<"REPEAT"<<endl;
return ;
}
id=tree[id].next[t];
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%s",a);
build(0,a);
}
cin>>m;
for(int i=1;i<=m;i++)
{
scanf("%s",b);
find(0,b);
}
return 0;
}