m = int(eval(input()))

for i in range(m):

    d = eval(input())

    trains = [d]

    for j in range(1, len(d)):

        trains.extend([d[:j][::-1] + d[j:], d[:j] + d[j:][::-1], d[:j][::-1] + d[j:][::-1], d[j:] + d[:j], d[j:][::-1] + d[:j], d[j:] + d[:j][::-1], d[j:][::-1] + d[:j][::-1]])

    print((len(set(trains))))
m = int(eval(input()))

for i in range(m):

    d = eval(input())

    trains = [d]

    for j in range(1, len(d)):

        f, b = d[:j], d[j:]

        rf, rb = f[::-1], b[::-1]

        trains.extend([rf+b, f+rb, rf+rb, b+f, rb+f, b+rf, rb+rf])

    print((len(set(trains))))
m = int(eval(input()))
for i in range(m):
    d = eval(input())
    trains = [d]
    for j in range(1, len(d)):
        trains.extend(
            [
                d[:j][::-1] + d[j:],
                d[:j] + d[j:][::-1],
                d[:j][::-1] + d[j:][::-1],
                d[j:] + d[:j],
                d[j:][::-1] + d[:j],
                d[j:] + d[:j][::-1],
                d[j:][::-1] + d[:j][::-1],
            ]
        )
    print((len(set(trains))))

m = int(eval(input()))
for i in range(m):
    d = eval(input())
    trains = [d]
    for j in range(1, len(d)):
        f, b = d[:j], d[j:]
        rf, rb = f[::-1], b[::-1]
        trains.extend([rf + b, f + rb, rf + rb, b + f, rb + f, b + rf, rb + rf])
    print((len(set(trains))))

-        trains.extend( -            [ -                d[:j][::-1] + d[j:], -                d[:j] + d[j:][::-1], -                d[:j][::-1] + d[j:][::-1], -                d[j:] + d[:j], -                d[j:][::-1] + d[:j], -                d[j:] + d[:j][::-1], -                d[j:][::-1] + d[:j][::-1], -            ] -        ) +        f, b = d[:j], d[j:] +        rf, rb = f[::-1], b[::-1] +        trains.extend([rf + b, f + rb, rf + rb, b + f, rb + f, b + rf, rb + rf])