http://poj.org/problem?id=1256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
bool comp(char a, char b){
if(tolower(a)==tolower(b)){
return a < b;
}else
return tolower(a)<tolower(b);
}
int main(){
// freopen("in.txt", "r", stdin);
int n;
string str;
cin>>n;
while(n--){
cin>>str;
sort(str.begin(), str.end(), comp);
do{
cout<<str<<endl;
}while(next_permutation(str.begin(), str.end(), comp));
}
return 0;
}