**2 人解决**，4 人已尝试。

**6 份提交通过**，共有 81 份提交。

**9.3** EMB 奖励。

**单点时限: **2.0 sec

**内存限制: **512 MB

Thinking-Bear gave a string of letters to the sister who admired in the heart. Sister looked at the string and said to Thinking-Bear: “I hope it is symmetrical”. Thinking-Bear decided to cut a continuous part from the original string and join to form a new necklace. A necklace is symmetrical if we can cut it into a palindrome.

Thinking-Bear can use magic. He can replace one letter to another letters. The magic can be used at most twice. Thinking-Bear want to know what’s the longest length of necklace he is able to capture. We assume that the length of the new necklace must be an odd number.

**Note: This problem is different from the original Metropolitan problem in that the necklace being cut is joined to form a new necklace, instead of the remaining part.**

Th first line of the input is $T$ ($1 \le T \le 100$), which stands for the number of test cases you need to solve.

Each test case contains a string $S$, indicates the necklace. ($2 \le |S| \le 100~000$).

**Notice:** $|S|$ can be $2$. $\sum |S|$ for all tests does not exceed $10^6$.

For each test case, output a number, meaning the longest length of symmetrical necklace he can capture.

Input

1 abcdaaa

Output

7

For the sample, he can replace one ltter to “abcbaaa”.

**2 人解决**，4 人已尝试。

**6 份提交通过**，共有 81 份提交。

**9.3** EMB 奖励。

题目标签