Palindrome Partition solution codeforces

Palindrome Partition solution codeforces

substring is a continuous and non-empty segment of letters from a given string, without any reorders.

An even palindrome is a string that reads the same backward as forward and has an even length. For example, strings “zz“, “abba“, “abccba” are even palindromes, but strings “codeforces“, “reality“, “aba“, “c” are not.

beautiful string is an even palindrome or a string that can be partitioned into some smaller even palindromes.

You are given a string 𝑠, consisting of 𝑛 lowercase Latin letters. Count the number of beautiful substrings of 𝑠.

Input

Each test contains multiple test cases. The first line contains the number of test cases 𝑡 (1𝑡1041≤�≤104). The description of the test cases follows.

The first line of each test case contains a single integer 𝑛 (1𝑛51051≤�≤5⋅105).

The second line of each test case contains a string 𝑠. String 𝑠 consists of only lowercase Latin letters and has a length of 𝑛.

It is guaranteed that the sum of 𝑛 over all test cases does not exceed 51055⋅105.

Palindrome Partition solution codeforces

For each test case print the number of beautiful substrings.

Example

input

Copy
6
6
abaaba
1
a
2
aa
6
abcdef
12
accabccbacca
6
abbaaa

output

Copy
3
0
1
0
14
6
Note

In the first test case, the beautiful substrings are “abaaba“, “baab“, “aa“.

In the last test case, the beautiful substrings are “aa” (counted twice), “abba“, “bb“, “bbaa“, “abbaaa“.

Leave a Reply

Your email address will not be published. Required fields are marked *