#include<iostream>
#include<cmath>
#include<math.h>
#include<string>
#include <fstream>
#include <cctype>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
	freopen("DATA2.txt","r",stdin);
	freopen("OUT2.txt","w",stdout);
	int x,y,z;
	char arr[5];
	string w;
	for(x=0;x<5;x++)
	{
		cin >> w;
		if(w.length()<=1)
		{
			cout << w << endl;
		}
		else
		{
			for(y=0;y<w.length();y++)
			{
				arr[y]=w[y];
			}
			z=1;
			for(y=0;y<w.length();y++)
			{
				z*=y+1;
			}
			while(z--)
			{
				for(y=0;y<w.length();y++)
				{
					cout <<arr[y];
				}
				cout << endl;
				next_permutation(arr, arr+w.length());
			}

		}
	}
	return(0);
}
