// cas O((N+1)! lg N)
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N;
	scanf(" %d",&N);
	vector<pair<long long,long long> > f(N);
	vector<int> p(N); // pouzita permutacia
	for(int i =0; i < N; i++) {
		p[i] =i;
		long long a;
		scanf(" %lld",&a);
		f[i].second =0LL;
		f[i].first =a;
		// zratam pocet cifier fragmentu
		while(a > 0LL) {a /=10LL; f[i].second++;}}
	set<long long> odp; 
	while(true) {
		// v lubovolnom poradi na seba nalepim fragmenty
		long long a =0LL,b =1LL; 
		for(int i =0; i < N; i++) {
			a +=f[p[i]].first*b;
			for(int j =0; j < f[p[i]].second; j++) b *=10LL;}
		odp.insert(a);
		if(!next_permutation(p.begin(),p.end())) break;}
	for(set<long long>::iterator it =odp.begin(); it != odp.end(); it++) printf("%lld\n",*it);
	return 0;}