#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
const int base = 311;
const int maxn = 1e6 + 5;
string s;
int Hash[maxn], Pow[maxn];
int mul(int a, int b)
{
return a * b % mod;
}
int gethash(int l, int r)
{
return (Hash[r] - mul(Hash[l - 1], Pow[r - l + 1]) + mod * mod) % mod;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--)
{
int ans = 0, n;
cin >> s;
Pow[0] = 1;
n = s.size();
Hash[0] = 1;
for(int i = 1; i <= n; i++)
{
Pow[i] = mul(Pow[i - 1], base);
Hash[i] = Hash[i - 1] * base + (s[i - 1] - 'a' + 1);
Hash[i] %= mod;
}
int l = 1, r = n, len = 1;
while(1)
{
if(l == r)
{
ans++;
break;
}
if(l > r) break;
while(gethash(l, l + len - 1) != gethash(r - len + 1, r))
{
len++;
}
// cout << l << ' ' << l + len - 1 << ' ' << r - len + 1 <<' '<< r << ' ' << len << '\n';
l = l + len;
r = r - len;
len = 1;
if(l - 1 < r + 1) ans += 2;
else ans++;
}
cout << ans << '\n';
}
// cout << gethash(1, 2) << ' ' << gethash(7, 8);
return 0;
}