#include <bits/stdc++.h>
using namespace std;
int main() {
string piece = "KQRRBBNN";
sort(piece.begin(), piece.end());
vector<string> cand;
do {
// the king is placed between the two rooks
int l = piece.find('R');
int r = piece.find_last_of('R');
int k = piece.find('K');
if (k < l || k > r) {
continue;
}
// the white bishop s are placed on opposite-colored squares
int b1 = piece.find('B');
int b2 = piece.find_last_of('B');
if (b1 % 2 == b2 % 2) {
continue;
}
cand.push_back(piece);
} while (next_permutation(piece.begin(), piece.end()));
string str;
while (cin >> str) {
if (str == "END") {
break;
}
cin >> *new int;
auto cur = cand;
while (1) {
double best = numeric_limits<double>::max();
string base;
if (cur.size() == 960) {
base = "RBBNNQKR";
} else {
// DONE UP HERE
for (auto x : cur) {
array<int, 9> freq{};
for (auto y : cur) {
int cnt = 0;
for (int i = 0; i < 8; i++) {
if (x[i] == y[i]) {
cnt++;
}
}
freq[cnt]++;
}
double sum = 0;
for (int x : freq) {
if (x) {
sum += x * sqrt(n);
}
}
if (sum < best) {
best = sum;
base = x;
}
}
}
cout << base << endl;
int num;
cin >> num;
if (num == 8) {
break;
}
vector<string> ncur;
for (auto x : cur) {
int cnt = 0;
for (int i = 0; i < 8; i++) {
if (x[i] == base[i]) {
cnt++;
}
}
if (cnt == num) {
ncur.push_back(x);
}
}
cur = move(ncur);
}
}
return 0;
}