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

string numbers[10], format;

void find_comb(int pos, string current) {
	if (current.size() == format.size()) {
		cout << current << "\n";
		return;
	}
	for(int i = 0; i  < numbers[format[pos] - '0'].size(); ++i) {
		find_comb(pos+1, current + numbers[format[pos] - '0'][i]);
	}
}

int main() {
	for (int i = 0; i < 10; ++i) {
		cin >> numbers[i];
		sort(numbers[i].begin(), numbers[i].end());
	}
	cin >> format;
	find_comb(0, "");
	return 0;
}