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

int compare( char *str1, char *str2);
void reverse( char *str);

int main(){
	char data[100][72], new_train[72], save_train[72], copy1[72], copy2[72];
	int n, len;
	int i, j, k, l;

	scanf("%d", &n);
	for( ; n > 0; n--){
		int sum = 1;
		scanf("%s", new_train);
		strcpy( save_train, new_train);
		len = strlen(save_train);
		//devide
		for( i = 1; i < len; i++){
			strcpy( copy1, save_train);
			copy1[i] = '\0';
			strcpy( copy2, &save_train[i]);

			//turn over
			for( j = 0; j < 4; j++){
				switch ( j ) {
					case 0:
						break;
					case 1:
						reverse( copy1 );
						break;
					case 2:
						reverse( copy1 );
						reverse( copy2 );
						break;
					case 3:
						reverse( copy1 );
						break;
				}
				for( k = 0; k < 2; k++){
					switch ( k ) {
						case 0:
							strcpy( new_train, copy1);
							strcpy( &new_train[i], copy2);
							break;
						case 1:
							strcpy( new_train, copy2);
							strcpy( &new_train[len-i], copy1);
							break;
					}
					//&#352;&#249;‘¶”&#187;’&#232;
					for( l = 0; l < sum; l++){
						if( strcmp( new_train, data[l]) == 0){
							break;
						}
					}
					if ( l == sum ){
						strcpy( data[sum], new_train);
						puts(new_train);
						sum++;
					}
				}
			}
		}
		printf("%d\n", --sum);
	}
	return 0;
}
//‘O&#338;&#227;”&#189;“]
void reverse( char *str){
	int i;
	char copy;
	int n = strlen(str);

	for( i = 0; i < n/2; i++){
		copy = *(str+i);
		*(str+i) = *(str+n-i-1);
		*(str+n-i-1) = copy;
	}
}
	//&#8226;¶&#381;&#353;—&#241;”&#228;&#352;r
int compare( char *str1, char *str2){
	while( *str1 != '\0'){
		if (*str1 != *str2) return 0;
		str1++;
		str2++;
	}
	return 1;
}