#include<iostream>
using namespace std;
int main() {
int x[101], m, a, v[11] = {0};
cin >> m;
for (int i = 1; i <= m; i++)
cin >> x[i];
cin >> a;
do {
v[a % 10]++;
a /= 10;
} while (a != 0);
for (int i = 1; i <= m; i++) {
int cx = x[i], xx[11] = {0}, sem = 1;
do {
xx[cx % 10]++;
cx /= 10;
} while (cx != 0);
for (int j = 0; j <= 9; j++)
if (xx[j] != v[j])
sem = 0;
if (sem == 1)
cout << x[i] << ' ';
}
return 0;
}