#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define SIZE 100000+10
int len;
char str[SIZE];
int next[SIZE];
void get_next()
{
int k = 0;
next[1] = 0;
for(int i = 2; i <= len; ++i)
{
if(k > 0 && str[k+1] != str[i])
{
k = next[k];
}
if(str[k+1] == str[i])
{
next[i] = ++k;
}
else
{
next[i] = 0;
}
}
for(int i = 1; i <= len; ++i)
{
// printf("%d\n", next[i]);
}
}
int main(int argc, char const *argv[])
{
int ncase ;
scanf("%d\n", &ncase);
while(ncase--)
{
scanf("%s",str+1);
len = strlen(str+1);
// printf("len : %d\n",len);
get_next();
int ss = len - next[len];
if (ss == len)
{
printf("%d\n", len);
}
else
if (len%ss == 0)
{
printf("0\n");
}
else
{
printf("%d\n", ss-(len%ss));
}
}
return 0;
}
循环节,主要还是Next数组