#include<stdio.h>
#include<string.h>
char t[1000];
void rxSort(char s[]){
int n=0,i, d,c, cnt[32];
for(d=1;d>-1;d--){
for(i=0;i<32;i++){
cnt[i]=0;
}
i=0;
while(s[2*i]){
//printf("%c=%d\n",s[2*i],s[2*i]-97);
cnt[s[2*i+d]-97]++;
i++;
}
c=i;
for(i=31;i>-1;i--){
//printf(">%d=%d %d\n",i,cnt[i],c);
c -= cnt[i];
//printf(">>%d=%d %d\n",i,cnt[i],c);
cnt[i]=c;
//printf(">>>%d=%d %d\n",i,cnt[i],c);
}
i=0;
while(s[2*i]){
//printf(">>%c=%d %d\n",s[2*i+d],s[2*i+d]-97, cnt[s[2*i+d]-97]);
t[2*cnt[s[2*i+d]-97]] = s[2*i];
t[2*cnt[s[2*i+d]-97]+1] = s[2*i+1];
cnt[s[2*i+d]-97]++;
i++;
}
//printf("%s %s\n",t, s);
}
}
int main(void) {
int i;
char s[1001];
while(i--){
rxSort(s);
}
return 0;
}
/*
int n[500];
void qsort(int left, int right, int pivot){
int t, l=left, r=right, p=pivot;
while(l<r){
while(n[l]<=n[p]&&l++<=r);
while(n[r]>n[p]&&r-->=l);
if(l>=r){
t=n[l]; n[l]=n[p]; n[p]=t;
qsort(left,l-1,l+(l-left)/2);
qsort(l+1,right,l+(right-l)/2);
}else{
t=n[l];n[l]=n[r]; n[r]=t;
}l++;r--;
}
}
int main(void) {
int i, j,k;
char s[1000];
scanf("%d",&i);
while(i--){
scanf("%s", &s);
j=0;
while(s[2*j]){
n[j] = s[2*j+1] + (s[2*j]<<8);j++;
}
qsort(0,j-1,j/2);
k=0;
while(k<j){
printf("%c%c", n[k]>>8,n[k]);
k++;
}
printf("\n");
}
return 0;
}
*/
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CmNoYXIgdFsxMDAwXTsKdm9pZCByeFNvcnQoY2hhciBzW10pewoJaW50IG49MCxpLCBkLGMsIGNudFszMl07Cglmb3IoZD0xO2Q+LTE7ZC0t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