

If two words have the same length then the word which comes first in 'TEXT' also comes first in the rearranged sentence.
The first line of input contains an integer 'T' denoting the number of test cases.
The first line of each test case contains a single sentence 'TEXT'.
For each test case, return the rearranged sentence.
1 <= T <= 5
1 <= | TEXT | <= 10^5
Where | 'TEXT' | denotes the length of the 'TEXT' sentence.
Time limit: 1 sec
The idea is to create an array of pairs, ‘WORD’, of size ‘N’. Where the first element of pair is word length and the second element is the starting index of word.
Now, start iterating over ‘TEXT’ starting from index 0 and maintain a variable ‘currentStart’ to store the starting index of the current word. Whenever you encounter space(“ “) say at index ‘C’, it means your current word starting from index ‘currentStart’ ends at index ‘C’ - 1 and its length is c - ‘currentStart’. Insert the pair { ‘C’ - ‘currentStart’, ‘currentStart' } in your 'WORD' array and update 'currentStart' with ‘C’ + 1 ( the starting index of next word). Repeat steps till the string ends.
Now, sort the 'WORD' array in increasing order of word length, if word length is the same for two words then sort them in increasing order of their starting index.
Now iterate over the 'WORD' array and for each ‘WORD[i]’ with value {a ,b}, start inserting characters of original text starting from index b and till index a + b - 1 ( as word length is a ) in your answer sentence say 'ANS'.
Make the first character of 'ANS' capital and return ‘ANS’.