BETA

Difficulty Level: Basic

Submissions: 101 Accuracy:

20.79%

Another Matrix Game
       

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.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Arun Tyagi

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.