#include <iostream>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <cstdio>
using namespace std;
#define INF 0x3f3f3f3f
int main() {
char str[8][5], a[10], c[10];
int b[10];
int n, m, con = 0;
while (cin >> n&&n) {
con++;
for (int i = 0; i < n; ++i) {
scanf("%s", str[i]);
}
scanf("%s", c);
cin >> m;
printf("S-Tree #%d:\n",con);
for (int i = 0; i < m; ++i) {
scanf("%s", a);
for (int i = 0; i < n; ++i) {
b[i + 1] = a[i] - '0';
}
int l = 1, r = 1 << n, t = 1 << (n - 1);
for (int i = 1; i <= n; ++i) {
if (b[i] == 1) {
l = l + t;
}
else {
r = r - t;
}
t >>= 1;
}
printf("%c", c[l - 1]);
}
printf("\n\n");
}
return 0;
}