


For the array [ “TUNA”, “TIGER”, “RABBIT”, “RAT”, “ANTEATER” ],
A possible circle can be:

The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains a single integer ‘N’, representing the size of the array.
The second line of each test case contains ‘N’ space-separated strings representing the words of the given array.
For each test case print ‘true’ if you can make a circle by rearranging the given words, else print ‘false’.
Output for each test case will be printed in a separate line.
You are not required to print anything, it has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 10^5
1 <= L <= 20
Where L is the length of each word in the given array.
It is guaranteed that the sum of N over all test cases doesn’t exceed 10^5.
Time Limit: 1 sec.
We will build a directed graph and for each word, we will add an edge from the first character to the last character in the graph. Now we just have to check whether the graph contains an Eulerian cycle or not. If it contains an Eulerian cycle, then we can form a circle.
The conditions for the existence of an Eulerian cycle in a directed graph are:
Eulerian Cycle: An Eulerian Cycle is a trail that starts and ends at the same graph vertex. In other words, it is a graph cycle that uses each graph edge exactly once.
You can learn more about Eulerian Cycle at the given link:
https://mathworld.wolfram.com/EulerianCycle.html
Algorithm: