#include <iostream>
#include <string>
using namespace std;
bool test(string instring,int nextCharIndex);
int main(void)
{
int cases,k=1;
string instring;
cin>>cases;
while (cases--)
{
cin>>instring;
k=1;
char firstchar=instring[0];
while(k<instring.length())
{
int nextCharIndex;
for(int i=k;i<instring.length();i++)
{
if(instring[i]==firstchar||(i==instring.length()-1))
{
nextCharIndex=i;
break;
}
}
if (nextCharIndex==instring.length()-1)
{
cout<<instring.length()<<endl;
if(cases!=0)
{
cout<<endl;
}
break;
}
else if (test(instring,nextCharIndex))
{
cout<<nextCharIndex<<endl;
if(cases!=0)
{
cout<<endl;
}
break;
}
else
{
k=nextCharIndex+1;
}
}
}
return 0;
}
bool test(string instring,int nextCharIndex)
{
if(instring.length()%nextCharIndex!=0)
{
return false;
}
for(int i=nextCharIndex,j=0;i<instring.length();i++)
{
if(instring[j]!=instring[i])
{
return false;
}
if(++j==nextCharIndex)
{
j=0;
}
}
return true;
}