#include<stdio.h>
#include<string.h>
int main()
{
  int m;
  scanf("%d",&m);
  int k;
  char s[100];
  int n;
  char ss[1000][100];
  int count;
  int ans;
  int i,j;
  char f;
  for(k=0;k<m;k++)
  {
    scanf("%s",s);
    n=strlen(s);
    count=0;
    for(i=0;i<n-1;i++)
    {
      for(j=0;j<=i;j++)
        ss[count][j]=s[j];
      for(j=i+1;j<n;j++)
        ss[count][j]=s[j];
      ss[count][n]='\0';
      count++;
      for(j=0;j<=i;j++)
        ss[count][j]=s[j];
      for(j=i+1;j<n;j++)
        ss[count][j]=s[n-j+i];
      ss[count][n]='\0';
      count++;
      for(j=0;j<=i;j++)
        ss[count][j]=s[i-j];
      for(j=i+1;j<n;j++)
        ss[count][j]=s[j];
      ss[count][n]='\0';
      count++;
      for(j=0;j<=i;j++)
        ss[count][j]=s[i-j];
      for(j=i+1;j<n;j++)
        ss[count][j]=s[n-j+i];
      ss[count][n]='\0';
      count++;
      for(j=i+1;j<n;j++)
        ss[count][j-i-1]=s[j];
      for(j=0;j<=i;j++)
        ss[count][j+n-i-1]=s[j];
      ss[count][n]='\0';
      count++;
      for(j=i+1;j<n;j++)
        ss[count][j-i-1]=s[n-j+i];
      for(j=0;j<=i;j++)
        ss[count][j+n-i-1]=s[j];
      ss[count][n]='\0';
      count++;
      for(j=i+1;j<n;j++)
        ss[count][j-i-1]=s[j];
      for(j=0;j<=i;j++)
        ss[count][j+n-i-1]=s[i-j];
      ss[count][n]='\0';
      count++;
      for(j=i+1;j<n;j++)
        ss[count][j-i-1]=s[n-j+i];
      for(j=0;j<=i;j++)
        ss[count][j+n-i-1]=s[i-j];
      ss[count][n]='\0';
      count++;
    }
    for(i=0;i<count-1;i++)
    {
      if(strcmp(ss[i],ss[i+1])>0)
      {
        for(j=0;j<n;j++)
        {
          f=ss[i][j];
          ss[i][j]=ss[i+1][j];
          ss[i+1][j]=f;
        }
        if(i>0)
          i-=2;
      }
    }
    ans=count;
    for(i=1;i<count;i++)
      if(strcmp(ss[i],ss[i-1])==0)
        ans--;
    printf("%d\n",ans);
  }
  return 0;
}
