# include<iostream>
# include<string>
# include<string.h>
# include<queue>
# include<stdio.h>
#include <algorithm>
using namespace std;
int d[][];
int main()
{
int n,m,i,j;
cin>>n;
while(n--)
{
char s1[],s2[];
scanf("%s",s1);
int len = strlen(s1)-;
for(i=len,j=;i>=;i--,j++)
s2[i] = s1[j]; for(i=;i<=len;i++)
{
for(j=;j<=len;j++)
{
if(s1[i]==s2[j])
{
if(i==||j==) d[i][j]= ;
else d[i][j] = d[i-][j-] + ;
}
else
{
if(i==&&j==)
{
d[i][j]= ;
continue;
}
if(i==)
{
d[i][j]= d[i][j-];
continue;
}
if(j==)
{
d[i][j]= d[i-][j];
continue;
}
if(d[i-][j]>=d[i][j-]) d[i][j] = d[i-][j];
else d[i][j] = d[i][j-];
}
}
}
printf("%d\n",len-d[len][len]+);
}
return ;
}