#include<iostream>
#include<cstring>
using namespace std;
int n,m,i,j,k;
const int N=8e6+5;
struct tree{
int son[27];
int num;
bool seg;
}t[N];
int x=1;
void insert(string s){
int cnt=0;
for(i=0;s[i];i++){
int ch=s[i]-'a';
if(t[cnt].son[ch]==0){
t[cnt].son[ch]= x++;
}
cnt=t[cnt].son[ch];
t[cnt].num++;
}
}
int find(string s){
int cnt=0;
for(i=0;s[i];i++){
int ch=s[i]-'a';
if(t[cnt].son[ch]==0){
return 2;
}
cnt=t[cnt].son[ch];
}
if(t[cnt].num == 0) return 2;
if(t[cnt].seg == false){
t[cnt].seg=true;
return 1;
}
return 3;
}
int main(){
cin>>n;
string s;
while(n--){
cin>>s;
insert(s);
}
cin>>m;
while(m--){
cin>>s;
k=find(s);
if(k==1) puts("OK");
if(k==2) puts("WRONG");
if(k==3) puts("REPEAT");
}
return 0;
}