

1) All words will have the exact same length.
2) Each word contains only lowercase English alphabet a-z.
The word sequence ["ball", "area", "lead", "lady"] forms a word square because each word reads the same both horizontally and vertically i.e.
b a l l
a r e a
l e a d
l a d y
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of every test case contains one integer ‘N’ where ‘N’ denotes the number of strings.
The second line of every test case contains ‘N’ space-separated strings.
For each test case, return all the valid word squares you can build from the string array.
1) You do not need to print anything, it has already been taken care of. Just return all the valid word squares.
1 <= T <= 10
1 <= N <= 10^3
1 <= |WORD| <= 5
Time Limit: 1 sec
Let's say we have words array = {"area","lead","wall","lady","ball"}
We know that the sequence contains 4 words because the length of each word is 4.
Every word can be the first word of the sequence, let's take "wall" for example.
Which word could be the second word? Must be a word starting with "a" (therefore "area"), because it has to match the second letter of the word "wall".
Which word could be the third word? Must be a word starting with "le" (therefore "lead"), because it has to match the third letter of the word "wall" and the third letter of the word "area".
What about the last word? Must be a word starting with "lad" (therefore "lady"). For the same reason above.