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.
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.
"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.
Head to tail ordering is possible.
The order will be : big geeks smart