#include <cstdio> #include <cstring> #include <string> #include <set> #include <algorithm> using namespace std; char S[10][100]; set<string> H; char key[100]; int L[10]; void dfs(int p, string w) { if (key[p] < '0' || key[p] > '9') { if (H.find(w) == H.end()) { printf("%s\n", w.c_str()); H.insert(w); } return; } for (int i=0; i<L[key[p]-'0']; ++i) { dfs(p+1, w + S[key[p]-'0'][i]); } } int main() { // freopen("test.in", "r", stdin); for (int i=0; i<10; ++i) { scanf("%s\n", S[i]); L[i] = strlen(S[i]); sort(S[i], S[i]+L[i]); } scanf("%s", &key); dfs(0, ""); return 0; }