Thinking-Bear's necklace
题号:NC17380
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Thinking-Bear gave a necklace to the sister who he admired in the heart. The necklace is made of the lowercase letter head-tail string.
Sister looked at the necklace and said to Thinking-Bear: "I hope it is symmetrical". Thinking-Bear decided to cut a continuous part from the original necklace, 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.

输入描述:

The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
Each test case contains a string S, indicates the necklace. (2 < |S| ≤ 100000).

输出描述:

For each test case, output a number, means the longest length of symmetrical necklace he can capture.
示例1

输入

复制
1
abcdaaa

输出

复制
7

说明

For the sample, he can replace one letter to ``abcbaaa".