#include <cstdio>
#include <cstring>
using namespace std;
const int MAXL = 1e6 + 2;
int counter[2 * MAXL], kk;
char s[MAXL * 2];
int LongestPalindrome()
{
int j = 0, _max = 0, ans = 0, len = kk;
counter[0] = 1;
for(int i = 1; i < len; i++){
int st = 1, cnt = 1;
if(2 * j >= i){
int low = counter[2 * j - i] < (counter[j] - 2 * (i - j)) ? counter[2 * j - i] : (counter[j] - 2 * (i - j));
cnt = cnt > low ? cnt : low;
}
st = cnt / 2 + 1;
for(int k = st; k <= i && k < len - i; k++)
{
if(s[i + k] == s[i - k])
cnt += 2;
else
break;
}
counter[i] = cnt;
ans = ans > cnt ? ans : cnt;
if(i + counter[i] / 2 > _max){
j = i;
_max = i + counter[i] / 2;
}
}
return ans / 2;
}
int main()
{
int n;
char ch;
scanf("%d", &n);
getchar();
for(int i = 0; i < n; i++)
{
kk = 0;
s[kk++] = '$';
while((ch = getchar()) != '\n'){
s[kk++] = ch;
s[kk++] = '$';
}
s[kk++] = '\0';
if(kk != 2)
printf("%d\n", LongestPalindrome());
}
return 0;
}