#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define SZ(S) ((int) ((S).size()))
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
string brail[10][3] = {
{".*", "**", ".."}, //0
{"*.", "..", ".."}, //1
{"*.", "*.", ".."}, //2
{"**", "..", ".."}, //3
{"**", ".*", ".."}, //4
{"*.", ".*", ".."}, //5
{"**", "*.", ".."}, //6
{"**", "**", ".."}, //7
{"*.", "**", ".."}, //8
{".*", "*.", ".."}, //9
};
int main() {
ios :: sync_with_stdio(false); cin.tie(NULL);
cout << (fixed) << setprecision(6);
int n;
while (cin >> n && n) {
char typ; cin >> typ;
// DEBUG(n);
// DEBUG(typ);
if (typ == 'S') {
string a[3];
REP(t,3) a[t] = "";
string dig; cin >> dig;
REP(i,dig.size()) {
int u = dig[i] - '0';
REP(t,3) {
if (i) a[t] += ' ';
a[t] += brail[u][t];
}
}
REP(t,3) cout << a[t] << endl;
}
else {
string a[3];
REP(t,3) {
a[t] = "";
REP(i,2*n) {
char c; cin >> c;
a[t] += c;
}
}
// PR0(a, 3);
REP(turn,n) {
int start = 2 * turn;
REP(dig,10) {
if (brail[dig][0] == a[0].substr(start,2)
&& brail[dig][1] == a[1].substr(start, 2)
&& brail[dig][2] == a[2].substr(start, 2)) {
cout << dig;
break;
}
}
}
cout << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIEZPUihpLGEsYikgZm9yKGludCBpPShhKSxfY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lKTsgY2luLnRpZShOVUxMKTsKICAgIGNvdXQgPDwgKGZpeGVkKSA8PCBzZXRwcmVjaXNpb24oNik7CiAgICBpbnQgbjsKICAgIHdoaWxlIChjaW4gPj4gbiAmJiBuKSB7CiAgICAgICAgY2hhciB0eXA7IGNpbiA+PiB0eXA7Ci8vICAgICAgICBERUJVRyhuKTsKLy8gICAgICAgIERFQlVHKHR5cCk7CiAgICAgICAgaWYgKHR5cCA9PSAnUycpIHsKICAgICAgICAgICAgc3RyaW5nIGFbM107CiAgICAgICAgICAgIFJFUCh0LDMpIGFbdF0gPSAiIjsKCiAgICAgICAgICAgIHN0cmluZyBkaWc7IGNpbiA+PiBkaWc7CiAgICAgICAgICAgIFJFUChpLGRpZy5zaXplKCkpIHsKICAgICAgICAgICAgICAgIGludCB1ID0gZGlnW2ldIC0gJzAnOwogICAgICAgICAgICAgICAgUkVQKHQsMykgewogICAgICAgICAgICAgICAgICAgIGlmIChpKSBhW3RdICs9ICcgJzsKICAgICAgICAgICAgICAgICAgICBhW3RdICs9IGJyYWlsW3VdW3RdOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIFJFUCh0LDMpIGNvdXQgPDwgYVt0XSA8PCBlbmRsOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgc3RyaW5nIGFbM107CiAgICAgICAgICAgIFJFUCh0LDMpIHsKICAgICAgICAgICAgICAgIGFbdF0gPSAiIjsKICAgICAgICAgICAgICAgIFJFUChpLDIqbikgewogICAgICAgICAgICAgICAgICAgIGNoYXIgYzsgY2luID4+IGM7CiAgICAgICAgICAgICAgICAgICAgYVt0XSArPSBjOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9Ci8vICAgICAgICAgICAgUFIwKGEsIDMpOwogICAgICAgICAgICBSRVAodHVybixuKSB7CiAgICAgICAgICAgICAgICBpbnQgc3RhcnQgPSAyICogdHVybjsKICAgICAgICAgICAgICAgIFJFUChkaWcsMTApIHsKICAgICAgICAgICAgICAgICAgICBpZiAoYnJhaWxbZGlnXVswXSA9PSBhWzBdLnN1YnN0cihzdGFydCwyKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgJiYgYnJhaWxbZGlnXVsxXSA9PSBhWzFdLnN1YnN0cihzdGFydCwgMikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICYmIGJyYWlsW2RpZ11bMl0gPT0gYVsyXS5zdWJzdHIoc3RhcnQsIDIpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvdXQgPDwgZGlnOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY291dCA8PCBlbmRsOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9Cgo=