


There will only be distinct characters in the given string.
First line contains an integer ‘T’ denoting the number of test cases.
First and the only line of the test case contains a string ‘S’.
Output contains an integer ‘X’ denoting the Lexicographic Permutation Rank of the given string.
You don’t need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 25
1 <= |S| <= 20
‘a’ <= S[i] <= ‘z’
Time Limit: 1 sec.
The above computations find the count of smaller strings. Therefore the rank of a given string “CODING” is the count of smaller strings plus 1. The final rank = 1 + 99 = 100.
The idea is to store the count of smaller elements in the right of each character in an auxiliary array in which the value at every index contains the count of smaller characters in the whole string.