#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m, idx;
string a;
struct Node{
int son[100];
bool flg;
bool vis;
}node[N];
void insert(int x, int y) {
if (y == a.length()) {
node[x].flg = true;
return;
}
if (node[x].son[a[y] - 'a']) insert(node[x].son[a[y] - 'a'], y + 1);
else {
node[x].son[a[y] - 'a'] = ++idx;
insert(idx, y + 1);
}
}
int find(int x, int y) {
if (y == a.length()) {
if (node[x].flg == true) {
if (node[x].vis) return 1;
node[x].vis = true;
return 0;
}
else return 2;
}
if (!node[x].son[a[y] - 'a']) return 2;
find(node[x].son[a[y] - 'a'], y + 1);
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a;
insert(1, 0);
}
cin >> m;
for (int i = 1; i <= m; ++i) {
cin >> a;
int s = find(1, 0);
if (s == 0) cout << "OK" << '\n';
if (s == 1) cout << "REPEAT" << '\n';
if (s == 2) cout << "WRONG" << '\n';
}
}