// Forked from http://d.hatena.ne.jp/sndr/20150112/1421067951

import std.stdio, std.string, std.conv, std.algorithm, std.range;
import std.container : RedBlackTree;

void main()
{
    foreach (m; 0..readln.chomp.to!int)
    {
        auto ans = new RedBlackTree!dstring();
        auto str = readln.chomp.to!dstring;
        foreach (i, c; str)
            foreach (x; [str[0..i].idup, str[0..i].retro.array.idup])
                foreach (y; [str[i..$].idup, str[i..$].retro.array.idup])
                    ans.insert([x~y, y~x]);
        ans.length.writeln;
    }
}