#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 72

/* Naive 0/1 Trie */

typedef struct trie *trie;
struct trie { trie children[26]; char flag; };

trie trie_cons(char* str, trie t)
{
    if(!t)
        t = (trie)calloc(1, sizeof(struct trie));

    if(*str)
        t->children[*str - 'a'] = trie_cons(str + 1, t->children[*str - 'a']);
    else
        t->flag = 1;

    return t;
}

int trie_count(trie t)
{
    if(!t)
        return 0;
    else
    {
        int res = (t->flag != 0), i;
        for(i = 0; i < 26; i++)
            res += trie_count(t->children[i]);
        return res;
    }
}

void trie_free(trie t)
{
    int i;

    if(t)
    {
        for(i = 0; i < 26; i++)
            trie_free(t->children[i]);
        free(t);
    }
}

/* --- */

void reverse(char* buf, int size)
{
    int i;
    char t;

    for(i = 0; i < size / 2; i++)
    {
        t = buf[i];
        buf[i] = buf[size - i - 1];
        buf[size - i - 1] = t;
    }
}

int main(void)
{
    trie t;
    int split_pos, len, i;
    char buf[MAX_LENGTH + 1], swapped[MAX_LENGTH + 1];

    scanf("%*d%*c");

    while(~scanf("%s%*c", buf))
    {
        t = NULL, len = strlen(buf);

        for(split_pos = 1; split_pos < len; split_pos++)
            for(i = 0; i < 4; i++)
            {
                /* reverse */
                if(i & 2) reverse(buf, split_pos);
                if(i & 1) reverse(buf + split_pos, len - split_pos);

                /* swap */
                memcpy(swapped, buf + split_pos, len - split_pos);
                memcpy(swapped + (len - split_pos), buf, split_pos);
                swapped[len] = '\0';

                /* push to the trie */
                t = trie_cons(buf, trie_cons(swapped, t));

                /* undo reverse */
                if(i & 2) reverse(buf, split_pos);
                if(i & 1) reverse(buf + split_pos, len - split_pos);
            }

        printf("%d\n", trie_count(t));
        trie_free(t);
    }

    return 0;
}