# ifdef _MSVC_LANG

# define _SCL_SECURE_NO_WARNINGS
# pragma warning( disable : 0325 ) // inline namespace Error

# endif


# include <iostream>
# include <string>
# include <iomanip>
# include <cstdio>
# include <array>
# include <numeric>
# include <algorithm>
# include <vector>
# include <functional>
# include <fstream>
# include <random>
# include <bitset>
# include <map>
# include <unordered_set>


// C++ 11 前提

using Ull = unsigned long long;
using Ll = long long;

template<typename T>
using Vec = std::vector<T>;

template<typename T, size_t L>
using Ary = std::array<T, L>;

namespace
{

    namespace meta
    {
        namespace coming
        {
            // c++ 17;
            template<class... _Types>
            using void_t = void;

            template<class _Ty,
                _Ty _Val>
                struct integral_constant
            {	// convenient template for integral constant types
                static constexpr _Ty value = _Val;

                using value_type = _Ty;
                using type = integral_constant;

                constexpr operator value_type() const noexcept
                {	// return stored value
                    return (value);
                }

                constexpr value_type operator()() const noexcept
                {	// return stored value
                    return (value);
                }
            };

            // c++ 17;
            template<bool _Val>
            using bool_constant = integral_constant<bool, _Val>;


            // c++ 14
            template<bool _Test,
                class _Ty = void>
                using enable_if_t = typename std::enable_if<_Test, _Ty>::type;
        }

        namespace core
        {

            template < class, class = void > struct enable_std_begin_end : std::false_type {};
            template < typename T >
            struct enable_std_begin_end<T,
                coming::void_t<decltype(std::begin(std::declval<const T&>()), std::end(std::declval<const T&>()))>> : std::true_type {}; // c++ 17


            template < class, class = void > struct enable_adl_begin_end : std::false_type {};
            template < typename T >
            struct enable_adl_begin_end<T,
                coming::void_t<decltype(begin(std::declval<const T&>()), end(std::declval<const T&>()))>> : std::true_type {};
        }

        template < typename T >
        struct is_range
            : coming::bool_constant< core::enable_std_begin_end<T>::value || core::enable_adl_begin_end<T>::value>
        {
        };

        /// <summary>
        /// ある値が0以上か
        /// </summary>
        template<class T, T num, class = std::nullptr_t> struct is_positive
            : coming::bool_constant<(num >= 0)>
        {
        };

    }


    inline namespace extension
    {
        inline namespace container_io
        {
            inline namespace in
            {

                /// <summary>
                /// for cin with STL container
                /// </summary>
                template< template<class ...> class Container, class ... Args, typename = meta::coming::enable_if_t<!std::is_same<Container<Args ...>, std::string>::value> >
                std::istream& operator >> (std::istream& is, Container<Args ...>& container)
                {
                    for (auto& elem : container) is >> elem; return is;
                }

                /// <summary>
                /// for cin with std::arary
                /// </summary>
                template<class T, size_t L>
                std::istream& operator >> (std::istream& is, std::array<T, L>& container)
                {
                    for (auto& elem : container) is >> elem; return is;
                }

                /// <summary>
                /// for cin with raw array
                /// </summary>
                template<class T, size_t L>
                std::istream& operator >> (std::istream& is, T(&ary)[L])
                {
                    for (int i{}; i < L; ++i) is >> ary[i]; return is;
                }

            }

            inline namespace out
            {
                namespace settings
                {
                    /// <summary>
                    /// 要素間の区切り文字
                    /// </summary>
                    const auto sepOfContainerElements{" "};
                    /// <summary>
                    /// コンテナ間の区切り文字
                    /// </summary>
                    const auto sepOfContainer{"\n"};
                }


                /// <summary>
                /// for cout Container with STL container
                /// </summary>
                template < template<class ...> class Container, class ... Args, typename = meta::coming::enable_if_t<!std::is_same<Container<Args ...>, std::string> ::value> >
                std::ostream& operator << (std::ostream& os, const Container<Args ...>& container)
                {
                    for (const auto& elem : container) os << elem << settings::sepOfContainerElements; return os;
                }

                /// <summary>
                /// for cout Container with std::array
                /// </summary>
                template < class T, size_t L>
                std::ostream& operator << (std::ostream& os, const std::array<T, L> container)
                {
                    for (const auto& elem : container) os << elem << settings::sepOfContainerElements; return os;
                }

                /// <summary>
                /// for cout Container with raw array
                /// </summary>
                template < class T, size_t L, typename = meta::coming::enable_if_t<!std::is_same<T, char>::value> >
                std::ostream& operator << (std::ostream& os, const T(&ary)[L])
                {
                    for (const auto& elem : ary) os << elem << settings::sepOfContainerElements; return os;
                }



                /// <summary>
                /// for cout Container in Container with STL container
                /// </summary>
                template < template<class ...> class Container1, class ... Cont1Args,
                    template<class ...> class Container2, class ... Cont2Args  >
                std::ostream& operator << (std::ostream& os, const Container1< Container2<Cont2Args ...>, Cont1Args ...>& container)
                {
                    for (const auto& elem : container) os << elem << settings::sepOfContainer; return os;
                }



                /// <summary>
                /// for cout Container in Container with std::array
                /// </summary>
                template < template<class ...> class Container, class ... Args, size_t L >
                std::ostream& operator << (std::ostream& os, const std::array<Container<Args ...>, L>& container)
                {
                    for (const auto& elem : container) os << elem << settings::sepOfContainer; return os;
                }
                /// <summary>
                /// for cout Container in Container with std::array
                /// </summary>
                template < template<class ...> class Container, class ... Args, size_t L, class T  >
                std::ostream& operator << (std::ostream& os, const Container<std::array<T, L>, Args ...>& container)
                {
                    for (const auto& elem : container) os << elem << settings::sepOfContainer; return os;
                }
                /// <summary>
                /// for cout Container in Container with std::array
                /// </summary>
                template < class T, size_t L1, size_t L2 >
                std::ostream& operator << (std::ostream& os, const std::array<std::array<T, L2>, L1> container)
                {
                    for (const auto& elem : container) os << elem << settings::sepOfContainer; return os;
                }


                /// <summary>
                /// for cout raw ary in raw ary
                /// </summary>
                template < class T, size_t L1, size_t L2 >
                std::ostream& operator << (std::ostream& os, const T(&ary)[L1][L2])
                {
                    for (size_t i{}; i < L1; ++i) os << ary[i] << settings::sepOfContainer; return os;
                }

            }
        }


        template<typename T, size_t L, typename Function>
        void for_each(T(&ary)[L], Function lambda)
        {
            for (size_t i{}; i < L; ++i)
                lambda(static_cast<T&>(ary[i]));
        }
    }


    inline namespace util
    {

        template<typename T>
        void SetAll(T& container, typename T::value_type value = typename T::value_type{})
        {
            for (typename T::reference content : container) content = value;
        }

        template<typename T, size_t L>
        void SetAll(T(&ary)[L], T value)
        {
            for (size_t i{}; i < L; ++i) ary[i] = value;
        }

        template<typename T, typename U, size_t L1, size_t L2>
        void SetAll(T(&ary)[L1][L2], U value)
        {
            for (size_t i{}; i < L1; ++i) SetAll(ary[i], value);
        }


    }


    inline namespace alg
    {
        bool IsPrime(const Ull n)
        {
            switch (n)
            {
            case 0: case 1:
                return false;
            case 2:
                return true;
            default:

                if (n % 2 == 0) return false;

                for (Ull i{3}; i * i <= n; i += 2)
                {
                    if (n % i == 0) return false;
                }
            }

            return true;
        }

        // 最大公約数
        Ull EuclideanAlg(Ull n1, Ull n2)
        {
            //if (n1 < 0 || n2 < 0) return 0;
            if (n2 > n1) std::swap(n1, n2);

            Ull r;
            while ((r = n1 % n2) != 0)
            {
                n1 = n2;
                n2 = r;
            }

            return n2;
        }

        // 最小公倍数
        Ull LCM(const std::vector<Ull>& values)
        {
            if (values.size() == 0)
                return 0;
            if (values.size() == 1)
                return values[0];
            if (values.size() == 2)
                return values[0] * values[1] / EuclideanAlg(values[0], values[1]);

            auto mid = values.cbegin() + values.size() / 2;

            return LCM(std::vector<Ull>{LCM(std::vector<Ull>(values.begin(), mid)), LCM(std::vector<Ull>(mid, values.end()))});
        }
    }


    void Solve();

}

# if true
int main()
{
    Solve();
    return 0;
}
# endif

namespace
{

    std::string reverseString(const std::string str)
    {
        std::string result;
        for (auto ite{str.crbegin()}; ite != str.crend(); ++ite) result += *ite;
        return result;
    }

    void Solve()
    {
        int n;
        std::cin >> n;

        for (int r{0}; r < n; ++r)
        {
            std::string str;
            std::cin >> str;

            Vec<std::string> trains(str.size() * 8 + 10);


            for (int i = 1; i < str.size(); ++i)
            {
                std::string right = str.substr(str.size() - i, i);
                std::string left = str.substr(0, str.size() - i);
                std::string rr = reverseString(right);
                std::string lr = reverseString(left);

                trains.push_back(right + left);
                trains.push_back(right + lr);
                trains.push_back(rr + left);
                trains.push_back(rr + lr);

                trains.push_back(left + right);
                trains.push_back(left + rr);
                trains.push_back(lr + right);
                trains.push_back(lr + rr);
                
            }

            std::sort(trains.begin(), trains.end());
            std::cout << (std::unique(trains.begin(), trains.end()) - trains.begin() - 1) << std::endl;

        }
    }

}


Measured memory_bytes: 3116