#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){ int n,ca=0; while(scanf("%d",&n),n) { int x[10],y[10]; for(int i=1;i<=n;i++) { char s[5]; scanf("%s",s); x[i]=s[1]-'0'; } char lef[1000],ans[1000]; scanf("%s",lef); int m,top=0; scanf("%d",&m); for(int i=0,now;i<m;i++) { char s[10]; scanf("%s",s); for(int j=0;s[j]!=' ';j++) y[j+1]=s[j]-'0'; now=1; for(int j=1;j<=n;j++) { if(y[x[j]]==0) now*=2; else now=now*2+1; } ans[top++]=lef[now-(1<<n)]; } ans[top++]=' '; printf("S-Tree #%d:n%snn",++ca,ans); } return 0;}