#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
using namespace std;

string key[10];
string s;

void f(int mesto, string out){
	for(int i=0; i<(int)key[s[mesto]-48].size(); i++){
		if(mesto == s.size()-1){
			cout<<(out+key[s[mesto]-48][i])<<endl;
		}
		else{
			f(mesto+1, out+key[s[mesto]-48][i]);
		}
	}
	return;
}
int main(){

	for(int i=0; i<10; i++){
		cin>>key[i];
		sort(key[i].begin(), key[i].end());
	}
	cin>>s;
	
	f(0, "");
	return 0;
}