import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int m;
    scan(m);

    foreach (i ; 0 .. m) {
        string s = readln.chomp;
        writeln(solve(s));
    }
}

int solve(string s) {
    int res;

    auto rbt = redBlackTree!(string)();

    foreach (i ; 1 .. s.length) {
        auto a = s[0..i].dup.to!(string), ar = s[0..i].dup.retro.to!(string);
        auto b = s[i..$].dup.to!(string), br = s[i..$].dup.retro.to!(string);

        rbt.insert(a~b);
        rbt.insert(a~br);
        rbt.insert(ar~b);
        rbt.insert(ar~br);
        rbt.insert(b~a);
        rbt.insert(b~ar);
        rbt.insert(br~a);
        rbt.insert(br~ar);
    }

    debug {
        writeln(rbt);
    }

    return rbt.length;
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}