1 #include
2 #include
3 #include
4 using namespace std;
5
6 char str[1005];
7 int dp[1005][1005];
8
9 int main(int argc, char const *argv[])
10 {
11 int n;
12 scanf("%d",&n);
13 while(n--) {
14 scanf("%s",str);
15 memset(dp, 0, sizeof(dp));
16 int len = strlen(str);
17 for(int l = 1; l ) {
18 for(int i = 0,j = l; i ) {
19 if(str[i] == str[j]) {
20 dp[i][j] = dp[i+1][j-1];
21 }
22 else {
23 dp[i][j] = min(dp[i+1][j],dp[i][j-1])+1;
24 }
25 }
26 }
27 printf("%d\n",dp[0][len-1]);
28 }
29 return 0;
30 }