题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4628
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
const int maxn =20+5;
const int mod=1e9+7;
int INF=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
char s[maxn];
int dp[1<<17],len;///状态的最优值
int cnt,jihe[1<<17];
bool isPalin(int S){char tmp[20];int idx=0;for(int i=0;i<len;i++) if(S&(1<<i))tmp[idx++]=s[i];int l=0,r=idx-1;while(l<=r){if(tmp[l]!=tmp[r]) return false;else l++,r--;}return true;
}
int Dp(int sta){if(dp[sta]<INF) return dp[sta];for(int i=0;i<cnt;i++) if((sta&jihe[i])==jihe[i])dp[sta]=min(Dp(sta^jihe[i]),dp[sta]);return ++dp[sta];}
int main(){int t;scanf("%d",&t);while(t--){memset(dp,0xf,sizeof(dp));INF=dp[0];dp[0]=0;scanf("%s",s);len=strlen(s);cnt=0;///将集合置为空for(int i=1;i<(1<<len);i++)if(isPalin(i)) jihe[cnt++]=i;printf("%d\n",Dp((1<<len)-1));}return 0;
}