#define ll long long voidgetnext(char *t, int *nxt) { nxt[0] = -1; int m = strlen(t + 1); for (int i = 1, j; i <= m; i++) { for (j = nxt[i - 1]; j >= 0 && t[j + 1] != t[i]; j = nxt[j]) ; nxt[i] = j + 1; } }
char t[N], s[N]; int nxt[N]; int pre[N], suf[N], cnt[27], len[N]; int to[27]; intmain() { int T; scanf("%d", &T); while (T--) { scanf("%s", s + 1); int n = strlen(s + 1);
for (int i = 1; i <= n; i++) nxt[i] = 0, len[i] = 1; getnext(s, nxt); memset(cnt, 0, sizeof(cnt)); memset(to, 0, sizeof(to)); int res = 0; for (int i = 1; i <= n; i++) { int o = s[i] - 'a'; res -= cnt[o] & 1; cnt[o]++; res += cnt[o] & 1; pre[i] = res; }
memset(cnt, 0, sizeof(cnt)); res = 0; for (int i = n; i >= 1; i--) { int o = s[i] - 'a'; res -= cnt[o] & 1; cnt[o]++; res += cnt[o] & 1; suf[i] = res; }