/* 
   AOJ 1142
   Organize Your Train part2
   2015/5/21
 */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define HASH_SIZE 701
struct node
{
  char str[73];
  struct node *next;
};

struct node *hash[HASH_SIZE];
int cnt = 0;



char front[73], back[73], output_str[73];

void storage_lines(int separating_num, char *input_str)
{
  int i, j;

  for(i = 0; i < 73; i++)
    {
      front[i] = '\0';
      back[i] = '\0';
    }
  
  for(i = 0; i < separating_num; i++)
    {
      front[i] = input_str[i];
    }

  for(j = 0; input_str[i] != '\0'; j++, i++)
    {
      back[j] = input_str[i] ;
    }

  //  printf("S: front=%s, back=%s\n", front, back);

}

void reversal_line(int reverse_pattern)
{
  int i, j, k;
  char tmp[73] = {'\0'};

  if(reverse_pattern == 1 || reverse_pattern == 3)
    {
      for(i = 0; front[i] != '\0'; i++)
	{
	  tmp[i] = front[i];
	}
      for(j = 0; i >= 0; j++, i--)
	{
	  front[j] = tmp[i - 1];
	}
      front[j - 1] = '\0';
    }
  
  if(reverse_pattern == 2)
    {
      for(i = 0; back[i] != '\0'; i++)
	{
	  tmp[i] = back[i];
	}
      for(j = 0; i >= 0; j++, i--)
	{
	  back[j] = tmp[i - 1];
	}
      back[j - 1] = '\0';
    }

  //  printf("R: front=%s, back=%s\n", front, back);

  
}

void departure_line(int departure_pattern)
{

  char prev_front[73], prev_back[73];
  
  
  if(departure_pattern == 0)
    {
      strcpy(prev_front, front);
      strcat(front, back);
      strcpy(output_str, front);
      strcpy(front, prev_front);
    }
  else
    {
      strcpy(prev_back, back);
      strcat(back, front);
      strcpy(output_str, back);
      strcpy(back, prev_back);
    }
}

int hash_calc(char *output_str)
{
  int i, sum = 0;

  for(i = 0; output_str[i] != '\0'; i++)
    {
      sum += output_str[i] * (i + 1) * 10;
    }
  //    printf("hash_calc \"%s\" = %d\n", output_str, sum % HASH_SIZE);
  return sum % HASH_SIZE;
}

void hash_search(int hash_val, char *output_str)
{
  struct node *next = NULL;
  if(hash[hash_val] == NULL)
    {
      //      printf("hoge\n");
      //      printf("output  \"%s\"\n", output_str);
      cnt++;
      hash[hash_val] = malloc(sizeof(*hash[hash_val]));
      strcpy(hash[hash_val]->str, output_str);
      hash[hash_val]->next = NULL;

    }
  else
    {
      //      printf("foo\n");
      next = hash[hash_val];
      if(strcmp(next->str, output_str) == 0)
	{
	  return ;
	}
      while(next->next != NULL)
	{
	  if(strcmp(next->str, output_str) == 0)
	    {
	      return ;
	    }
	  next = next->next;
	}
            if(strcmp(next->str, output_str) == 0)
	{
	  return ;
	}
	    //      printf("output  \"%s\"\n", output_str);
      cnt++;
      next->next = malloc(sizeof(*next->next));
      strcpy(next->next->str, output_str);
    }
  
  return ;
}

void search(char *input_str)
{
  int i, j, k, hash_val;
  for(i = 0; i < HASH_SIZE; i++)
    {
      hash[i] = NULL;
    }

  for(i = 1; i < strlen(input_str); i++)
    {
      storage_lines(i, input_str);
      for(j = 0; j < 4; j++)
	{
	  reversal_line(j);
	  for(k = 0; k < 2; k++)
	    {
	      departure_line(k);
	      //	      printf("%s\n", output_str);
	      hash_val = hash_calc(output_str);
	      hash_search(hash_val, output_str);
	    }
	}
    }
}

int main(void)
{
  
  int num, i, ans;
  char input_str[73];
  scanf("%d", &num);
  for(i = 0; i < num; i++)
    {
      cnt = 0;
      scanf("%s", input_str);
      search(input_str);
      printf("%d\n", cnt);
    }
  return 0;
}

Measured memory_bytes: 3576