import std.stdio;
import std.conv;
import std.string;

void main(){
    foreach(i; 0..readln.chomp.to!int){
        bool[string] set;
        string input = readln.chomp;
        foreach(j; 1..input.length){
            auto s1 = input[0..j];
            auto s2 = input[j..$];
            auto r1 = input[0..j].dup.reverse.idup;
            auto r2 = input[j..$].dup.reverse.idup;
            set[s1 ~ s2] = set[s1 ~ r2] = set[r1 ~ s2] = set[r1 ~ r2] = set[s2 ~ s1] = set[s2 ~ r1] = set[r2 ~ s1] = set[r2 ~ r1] = true;
        }
        set.length.writeln;
    }
}