You are given a ternary string S of length N consisting of 0, 1, and 2. Your task is to determine the number of distinct permutations of S for which satisfies the below condition:
Let R be the permutation of S, R is valid if the count of all palindromic substrings (sizes from 1 to N) does not exceed N.
Input format
Output format
Print T lines. For each test case:
Constraints
1≤T≤20000
1≤N≤200000
The sum of the length of strings over all test cases does not exceed 200000.
First test case: All the permutations of this string are different and valid.
"012","021","102","120","210" and "201".
Second test case: Two permutations are valid.
"12012" and "21021"
In each of the above strings there are only 1 length palindromes, which is equal to length of string.