Nobita and the Alien Dictionary
All submissions for this problem are available.
Our Friend, Nobita one day followed a mysterious light in sky and followed it to the forest. Suddenly the light brightened up more and something dropped down out of it and whoosh..! The light vanished. Scared, yet brave, Nobita walked towards the 'thing' and took it home to show it to Doraemon. Back home, he told Doraemon about whatever happened and showed the 'thing' to Doraemon. Now, our intelligent friend Doraemon after examining the 'thing' explained Nobita that what he followed was a UFO and this 'thing' is a book with English alphabets but not English words. On carefully examining it, he found it to be an 'alien dictionary' scripted in roman but the order of alphabets was not following the English alphabet pattern 'A,B,C,D...'. Now Doraemon has challenged Nobita to find the order of alphabets in the 'alien dictionary' while he takes a power nap. Nobita, after hours of hardwork, still could not find the answer. Please help him find the answer before Doraemon is awake.
The first line contains t, the number of test cases. Then t test cases follow.
Each test case has the following form:
-The first line contains n, the number of words.
-Then n lines follow, each line contains a word from dictionary
For each test case, print the order in which alphabets occur separated by a single space
For Invalid test cases, print "INVALID"
- 1 ≤ T ≤ 1000
- 1 ≤ n ≤ 500
- 1 ≤ |word| ≤ 50
Each word consists of [a-z]
Input: 4 3 caa aaa aab 4 daa aaa aba caa 5 baa abcd abca cab cad 3 aba bba aaa Output: c a b INVALID b d a c INVALID
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5|
Fetching successful submissions
If you are still having problems, see a sample solution here.