Codeforces Round 872 (Div. 2)
A
LuoTianyi and the Palindrome String
Codeforces
800
原题
←B →
翻译中…

LuoTianyi gives you a palindrome$^{\dagger}$ string $s$, and she wants you to find out the length of the longest non-empty subsequence$^{\ddagger}$ of $s$ which is not a palindrome string. If there is no such subsequence, output $-1$ instead.

翻译中…

$^{\dagger}$ A palindrome is a string that reads the same backward as forward. For example, strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.

翻译中…

$^{\ddagger}$ A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters from $b$. For example, strings "a", "aaa", "bab" are subsequences of string "abaab", but strings "codeforces", "bbb", "h" are not.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The description of test cases follows.

翻译中…

The first and the only line of each test case contains a single string $s$ ($1 \le |s| \le 50$) consisting of lowercase English letters — the string that LuoTianyi gives you. It's guaranteed that $s$ is a palindrome string.

翻译中…

Output

翻译中…

For each test case, output a single integer — the length of the longest non-empty subsequence which is not a palindrome string. If there is no such subsequence, output $-1$.

翻译中…

Note

翻译中…

In the first test case, "abcaba" is a subsequence of "abacaba" as we can delete the third letter of "abacaba" to get "abcaba", and "abcaba" is not a palindrome string. We can prove that "abcaba" is an example of the longest subsequences of "abacaba" that isn't palindrome, so that the answer is $6$.

翻译中…

In the second test case, we can only get "a" and "aa", but they are all palindrome strings, so the answer is $-1$.

翻译中…

样例

Input #1
4
abacaba
aaa
codeforcesecrofedoc
lol
Output #1
6
-1
18
2
InputCopy OutputCopy
题目信息
题号
1825A
时间限制
1 s
内存限制
256 MB
标签
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。