#include<stdio.h>
#include<string.h>


char *reverse(char *s) {

	int i;
	char answer[strlen(s)];
	int length = strlen(s);

	memset(answer,'\0',sizeof(char));

	for(i=0;i<=strlen(s)-1;i++)
		answer[i]=s[strlen(s)-1-i];

	strcpy(s,answer);
	s[length] = '\0';
	return s;
}

int main() {

	int m;
	char c[80];
	char s1[80],s2[80];
	char temp1[80],temp2[80];
	char s1_rev[80],s2_rev[80];
	char A[600][80];
	int a,i,j,k,l,x;
	int A_max;
	int answer;
	int length;

	scanf("%d\n",&m);

	//???????????????????????§?¨????????§?
	for(a=0;a<m;a++) {

		answer=0; //??????;
		fgets(c,sizeof(c),stdin);
		c[strlen(c)-1]='\0';
		length = strlen(c);

		for(i=0;i<600;i++)
			for(j=0;j<73;j++)
				A[i][j]='\0';

		//???????????????
		for(j=1;j<strlen(c);j++) {
			for(x=1;x<=8;x++){
				memset(s1,'\0',sizeof(char));
				memset(s2,'\0',sizeof(char));
				memset(temp1,'\0',sizeof(char));
				memset(temp2,'\0',sizeof(char));
				memset(s1_rev,'\0',sizeof(char));
				memset(s2_rev,'\0',sizeof(char));

				strncpy(s1,c,j);
				strncpy(s2,c+j,strlen(c)-j+1);
				s1[j]='\0';
				s2[strlen(c)-j+1]='\0';
				strcpy(temp1,s1);
				strcpy(temp2,s2);
				strcpy(s1_rev,reverse(temp1));
				strcpy(s2_rev,reverse(temp2));

				switch(x) {
				case 1:
					//s1,s2????????????(c)
					strcpy(A[8*(j-1)],c);
					break;
				case 2:
					//s1???????????¢
					strcpy(A[8*(j-1)+1],strcat(s1_rev,s2));
					break;
				case 3:
					//s2???????????¢
					strcpy(A[8*(j-1)+2],strcat(s1,s2_rev));
					break;
				case 4:
					//s1,s2???????????¢
					strcpy(A[8*(j-1)+3],strcat(s1_rev,s2_rev));
					break;
					//????????????s1,s2?????¢
				case 5:
					//s1.s2????????????
					strcpy(A[8*(j-1)+4], strcat(s2,s1));
					break;
					//s1???????????¢
				case 6:
					strcpy(A[8*(j-1)+5],strcat(s2_rev,s1));
					break;
					//s2???????????¢
				case 7:
					strcpy(A[8*(j-1)+6],strcat(s2,s1_rev));
					break;
				case 8:
					//s1,s2???????????¢
					strcpy(A[8*(j-1)+7],strcat(s2_rev,s1_rev));
					break;
				}
			}
		}
		A_max=8*(strlen(c)-1);

		for(k=0;k<A_max;k++) {
			if(k==0)
				answer++;
			else {
				for(l=0;l<k;l++) {
					if(!strcmp(A[l],A[k]))
						break;
					else if(l==k-1) {
						//printf("%d\n",k);
						answer++;
					}
				}
			}

		}
		printf("%d\n",answer);
	}

	return 0;
}