#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<bits/stdc++.h>
#include<cmath>
#include<algorithm>
using namespace std;
map<string,int>hash2;
typedef long long ll;
int q,n,t[800005][65],cnt[800005];
int idx=0;
char s[800005];
int getnum(char x)
{
if(x>='A'&&x<='Z')
return x-'A';
else if(x>='a'&x<='z')
return x-'a'+26;
else
return x-'0'+52;
}
void insert(char str[])
{
int root=0;
int len=strlen(str);
for(int i=0;i<len;i++)
{
int c=getnum(str[i]);
if(!t[root][c])
t[root][c]=++idx;
root=t[root][c];
}
cnt[root]=1;
}
int find(char str[])
{
int root=0;
int len=strlen(str);
for(int i=0;i<len;i++)
{
int c=getnum(str[i]);
if(!t[root][c])
{
cout<<"WRONG"<<endl;
break;
}
root=t[root][c];
if(i==len-1&&cnt[root]==2)
cout<<"REPEAT"<<endl;
if(i==len-1&&cnt[root]==1)
{
cnt[root]=2;
cout<<"OK"<<endl;
}
}
return cnt[root];
}
void solve()
{
int T;
cin>>T;
for(int i=1;i<=T;i++)
{
cin>>s;
insert(s);
}
cin>>q;
for(int i=1;i<=q;i++)
{
cin>>s;
find(s);
}
}
int main()
{
solve();
}