/*
 * Copyright (c) 2006 Kamo Hiroyasu
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *  An answer to ACM/ICPC Domestic Contest 2006 Problem B
 *	Organaize Your Train part II
 *
 *  Author: Kamo Hiroyasu <wd@ics.nara-wu.ac.jp>
 */

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

#define MAX_LENGTH	72
#define INPUT_FORMAT	"%72s"	/* should be "% MAX_LENGTH s" */

void *
memrevcpy(void *dst, const void *src, size_t len)
{
	char		*p = dst;
	const char	*q = src;
	size_t		i, j;

	for (i = 0, j = len - 1; i < len; i ++, j --) {
		p[i] = q[j];
	}
	return dst;
}

static int
search_configuration(char (*set)[MAX_LENGTH + 1], const char *str)
{
	char	(*p)[MAX_LENGTH + 1];

	for (p = set; strcmp(*p, str) != 0; p ++) {
	}
	return p - set;
}

int
count_configuration(const char *s)
{
	char	set[(MAX_LENGTH - 1) * 6 + 2][MAX_LENGTH + 1];
	int	count = 0;
	int	i, j, l;

	l = strlen(s);
	memcpy(set[0], s, l);
	set[0][l] = '\0';
	memrevcpy(set[1], s, l);
	set[1][l] = '\0';
	if (search_configuration(set, set[1]) == 1) {
		count = 1;
	}
	for (i = 1, j = l - 1; i < l; i ++, j --) {
		memrevcpy(set[count], s, i);
		memcpy(set[count] + i, s + i, j);
		set[count][l] = '\0';
		if (search_configuration(set, set[count]) == count) {
			count ++;
		}
		memcpy(set[count], s, i);
		memrevcpy(set[count] + i, s + i, j);
		set[count][l] = '\0';
		if (search_configuration(set, set[count]) == count) {
			count ++;
		}
		memrevcpy(set[count], s, i);
		memrevcpy(set[count] + i, s + i, j);
		set[count][l] = '\0';
		if (search_configuration(set, set[count]) == count) {
			count ++;
		}
		memcpy(set[count], s + i, j);
		memcpy(set[count] + j, s, i);
		set[count][l] = '\0';
		if (search_configuration(set, set[count]) == count) {
			count ++;
		}
		memcpy(set[count], s + i, j);
		memrevcpy(set[count] + j, s, i);
		set[count][l] = '\0';
		if (search_configuration(set, set[count]) == count) {
			count ++;
		}
		memrevcpy(set[count], s + i, j);
		memcpy(set[count] + j, s, i);
		set[count][l] = '\0';
		if (search_configuration(set, set[count]) == count) {
			count ++;
		}
	}
	return count;
}

main()
{
	int	n;
	char	buf[MAX_LENGTH + 1];

	scanf("%d", &n);
	for (; n > 0; n --) {
		scanf(INPUT_FORMAT, buf);
		printf("%d\n", count_configuration(buf));
	}
	return 0;
}
