/*一道比较水的字符串模拟。
刚开始的时候题意有点看错了。
就是注意在有重组可以相同的字符串的时候要把原有的字符串也删除掉。
这里用标记。
只要将每个字母重排就可以了。
还有大小写并没有区分在匹配的时候。*/
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
char a[1001][21];
char b[1001][21];
int main()
{
char s[22];
char temp1[22];
scanf("%s",s);
int h=0;
strcpy(a[h],s);//a作为原来的数组
char c;
for(int i=0; i<strlen(s); i++)
{
for(int j=i; j<strlen(s); j++)
{
if(s[i]>s[j])
{
c=s[i];
s[i]=s[j];
s[j]=c;
}
}
}
strcpy(b[h],s);
h++;
while(scanf("%s",s)==1)
{
if(s[0]=='#') break;
strcpy(temp1,s);
for(int i=0; i<strlen(s); i++)
{
if(s[i]>='A'&&s[i]<='Z')
s[i]=s[i]+32;
}
for(int i=0; i<strlen(s); i++)
{
for(int j=i; j<strlen(s); j++)
{
if(s[i]>s[j])
{
c=s[i];
s[i]=s[j];
s[j]=c;
}
}
}
bool ret=0;
for(int i=0; i<=h-1; i++)
{
if(strcmp(s,b[i])==0)
{
ret=1;
a[i][0]='*';
break;
}
}
if(ret==0)
{
strcpy(a[h],temp1);
strcpy(b[h],s);
h++;
}
}
char te[22];
for(int i=0; i<h; i++)
{
if(a[i][0]!='*')
{
for(int j=i; j<h; j++)
{
if(a[j][0]!='*')
{
if(strcmp(a[i],a[j])>0)
{
strcpy(te,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],te);
}
}
}
}
}
for(int i=0; i<h; i++)
{
if(a[i][0]!='*')
printf("%s\n",a[i]);
}
return 0;
}