BETA

Difficulty Level:

Hard

Total Submissions: 1841 Accuracy:

22.22%

Head to Tail ordering
       

A head to tail ordering of strings is the one in which the last letter of the previous word is the same as the first letter of the following word. For eg. ‘Geekforgeeks’ can be followed by ‘ software’.

The task is to write a code to accept a set of finite strings and determine if such an ordering is possible by arranging them in a head to tail sequence.

Input:
The first line contains an integer 'T' denoting the total number of test cases. In each test cases, the first line contains an integer 'N' denoting the size of array. The next 'N' lines contains N strings. Only letters 'a' through 'z' will appear in the word. The same word may appear several times in the list.


Output:
"Head to tail ordering is possible." if it is possible to arrange all the words in a sequence such that the first letter of each word is equal to the last letter of the previous word. All the plates from the list must be used, each exactly once else output "Head to tail ordering is not possible.". Output of all the test cases should be in a seperate line and dont print quotes.


Constraints:
1<=T<=200
1<=N<=100
1<=Length(String)<=100


Example:
Input:
1
3
big
smart
geeks

Output:
Head to tail ordering is possible.

Explaination :
The order will be : big  geeks  smart

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

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.