Another Matrix Game
Basic Accuracy: 25.81% Submissions: 155 Points: 1

Given a string S which contains only small letters. The task is to make a square matrix from string S. Then perform the following operations.
1. In each column delete the characters which occur more than one.
2. Column-wise sort the remaining characters in order abcd....wxyz. But print them in order azbycxdw....  
For example, after operation 1 if the remaining characters in a column are cedjki then after sorting they become cdeijk , now when printed in the given order the output will be ckdjei .

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a string S as input.


Output:
For each test case, in a new line print the above operations result. If there is no character left in the  matrix after operation 1 then print "0".


Constraints:
1 <= T <= 300
1 <= S <= 1000


Example:
Input:
3
adgkbdhlceilcfjm
aaaabbbcccdd
abcabcabc

Output:
abefgjhikm
acbacbadbadc
0

Explanation:
In 1st test case
Matrix will be
a d g k
b d h l
c e i  l
c f  j m
In 1st column 'c', in 2nd column 'd' and in 4th column 'l' has occurred more than once. So after deleting them and sorting the remaining characters the matrix become

   a - g  k
   b - h  -
   - e i   -
   - f  j  m

So after operation 2 we get 'ab' from 1st column, 'ef' from 2nd column, 'gjhi' from 3rd column and 'km' from 4th column. Appending all of them we get the output as  "abefgjhikm".
In 3rd test case  
Matrix will be
a b c
a b c
a b c
So the output will be 0.

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.