https://www.cnblogs.com/chenxiwenruo/p/3546457.html
int nxt[maxn];
char P[maxn];
void buildNext(int &m){
m=strlen(P+1);
int j=0;
nxt[1]=0;
rep(i,2,m){
while(j>0&&P[i]!=P[j+1]) j=nxt[j];
if(P[i]==P[j+1])j++;
nxt[i]=j;
}
}
int main(){
int t=read();
while(t--){
s1(P);
int m;
buildNext(m);
int cir=m-nxt[m];
if(cir!=m&&m%cir==0) println(0);//
else println(cir-nxt[m]%cir);
}
return 0;
}