

1. A subsequence of string S is a string which we get after removal of zero or more characters from S, and without changing the order of character in the remaining string.
2. A subsequence S’ of string S, is known as Power Subsequence if S’ can be represented in the form ‘A’^i + ‘B’^j + ‘C’^k where i, j and k are strictly greater than 0, ie. S’ can be written as a concatenation of I ‘A’s, followed by j ‘B’s, followed by k ‘C’s.
3. Eg. “ABC” is a Power Subsequence with i=j=k=1, while “BAC” or “AB” or “BC” are not Power Subsequences.
4. Two subsequences are considered different if and only if the set of indexes of string S, chosen for two subsequences, are different.
The first line of the input contains an integer T denoting the number of test cases.
The first and only line of each test case consists of a string S.
For each test case, print an integer that denotes the count of the number of Power Subsequences of the given string S in a separate line.
As the number of Power Subsequences can be large that's why print it modulo 10^9 +7.
You don't have to print anything, it has already been taken care of. Just Implement the given function.
1 <= T <= 100
1 <= |S| <= 10^4
Were |S| denotes the length of given string S.
Time Limit: 1 sec
Eg. for string “ABC '', let's assume solve is the name of our recursive function.
solve(“ABC”, 0, “”)
solve(“ABC”, 1, “”)
solve(“ABC”, 2, “”)
solve(“ABC”, 3, “”)
Return 0
solve(“ABC”, 3, “C”)
Return 0
Return 0
solve(“ABC”, 2, “B”)
solve(“ABC”, 3, “B”)
Return 0
solve(“ABC”, 3, “BC”)
Return 0
Return 0
Return 0
solve(“ABC”, 1, “A”)
solve(“ABC”, 2, “A”)
solve(“ABC”, 3, “A”)
Return 0
solve(“ABC”, 3, “AC”)
Return 0
Return 0
solve(“ABC”, 2, “AB”)
solve(“ABC”, 3, “AB”)
Return 0
solve(“ABC”, 3, “ABC”)
Return 1 // Because ABC is a power subsequence.
Return 1
Return 1
Return 1
This way we get 1 as the count of power subsequences.