#include <bits/stdc++.h>

bool validatee(const std::string& s, const std::vector<int>& st)
{
    auto validate = std::vector<int>(st.size());

    bool valid = true;
    for (unsigned i = 0; i < st.size(); ++i)
    {
        if (validate[st[i]] == s[i])
        {
            std::printf("invalid: duplicate st[%d]=%d <-> s[%d]=%d\n",
                i, st[i], i, s[i]);
            valid = false;
        }
        validate[st[i]] = s[i];
    }
    return valid;
}

//std::vector<int> solve(const std::string& s)
//{
//    // special case s = 1
//    if (s.size() == 1)
//    {
//        //std::cout << 1 << '\n' << 1 << '\n';
//        return {1};
//    }
//    // special case s = 2
//    if (s.size() == 2)
//    {
//        if (s[0] == s[1])
//        {
//            //std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
//            return {1,2};
//        }
//        else
//        {
//            //std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
//            return {1,1};
//        }
//
//    }
//
//    // keep track of belongness to each subseq
//    auto states = std::vector<int>(s.size());
//
//
//    // keep track of tails
//    auto tails = std::vector<int>();
//    tails.reserve(s.size());
//
//    int ctr=1;
//
//    states[0] = 1;
//
//    for (unsigned i = 1; i < s.size(); ++i)
//    {
//        if (s[i] == s[i-1])
//        {
//            bool fitting_tail=false;
//            for (unsigned j = 0; j < tails.size(); ++j)
//            {
//                if (s[tails.at(j)] != s[i])
//                {
//                    states[i] = states[tails.at(j)];
//                    tails[j] = i;
//                    fitting_tail = true;
//                    break;
//                }
//            }
//            if (!fitting_tail)
//            {
//                states[i] = ++ctr;
//            }
//            if (auto res = std::find(tails.begin(),tails.end(), i-1); res == tails.end()
//                    || tails.empty())
//                tails.push_back(i-1);
//        }
//        else
//        {
//            bool extend_tail = false;
//            for(unsigned j = 0; j < tails.size(); ++j)
//            {
//                if (tails.at(j) == i-1)
//                {
//                    states[i] = states[tails.at(j)];
//                    tails.at(j) = i;
//                    extend_tail = true;
//                    break;
//                }
//            }
//            if (!extend_tail)
//                states[i] = ctr;
//        }
//    }
//
//    return states;
//}

std::vector<int> solve3(const std::string& s)
{
    // special case s = 1
    if (s.size() == 1)
    {
        //std::cout << 1 << '\n' << 1 << '\n';
        return {1};
    }
    // special case s = 2
    if (s.size() == 2)
    {
        if (s[0] == s[1])
        {
            //std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
            return {1,2};
        }
        else
        {
            //std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
            return {1,1};
        }

    }

    // keep track of belongness to each subseq
    auto states = std::vector<int>(s.size());

    // keep track of tails
    //auto tails = std::vector<int>();
    //tails.reserve(s.size());
    auto tails = std::set<int>();

    int ctr=1;

    states[0] = 1;

    for (unsigned i = 1; i < s.size(); ++i)
    {
        if (s[i] == s[i-1])
        {
            bool fitting_tail=false;
            for (auto j = tails.begin(); j != tails.end(); ++j)
            {
                if (s[*j] != s[i])
                {
                    states[i] = states[*j];
                    tails.erase(*j);
                    tails.insert(i);
                    fitting_tail = true;
                    break;
                }
            }
            if (!fitting_tail)
            {
                states[i] = ++ctr;
            }
            tails.insert(i-1);
        }
        //else
        //{
        //    bool extend_tail = false;
        //    for (auto j = tails.begin(); j != tails.end(); ++j)
        //    {
        //        if (*j == i-1)
        //        {
        //            states[i] = states[*j];
        //            tails.erase(i-1);
        //            tails.insert(i);
        //            extend_tail = true;
        //            break;
        //        }
        //    }
        //    if (!extend_tail)
        //        states[i] = ctr;
        //}
        else
        {
            bool extend_tail = false;
            if (auto j = tails.find(i-1); j != tails.end())
            {
                states[i] = states[*j];
                tails.erase(i-1);
                tails.insert(i);
                extend_tail = true;
            }
            if (!extend_tail)
                states[i] = ctr;
        }
    }
    return states;
}

void solve2()
{
    int t; std::cin >> t;
    while (t--)
    {
        int trash; std::cin >> trash;
        std::string s;
        std::cin >> s;

        // special case s = 1
        if (s.size() == 1)
        {
            std::cout << 1 << '\n' << 1 << '\n';
            continue;
        }
        // special case s = 2
        if (s.size() == 2)
        {
            if (s[0] == s[1])
            {
                std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
                continue;
            }
            else
            {
                std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
                continue;
            }

        }

        // keep track of belongness to each subseq
        auto states = std::vector<int>(s.size());

        // keep track of tails
        //auto tails = std::vector<int>();
        //tails.reserve(s.size());
        auto tails = std::set<int>();

        int ctr=1;

        states[0] = 1;

        for (unsigned i = 1; i < s.size(); ++i)
        {
            if (s[i] == s[i-1])
            {
                bool fitting_tail=false;
                for (auto j = tails.begin(); j != tails.end(); ++j)
                {
                    if (s[*j] != s[i])
                    {
                        states[i] = states[*j];
                        //*j = i;
                        tails.erase(*j);
                        tails.insert(i);
                        fitting_tail = true;
                        break;
                    }
                }
                if (!fitting_tail)
                {
                    states[i] = ++ctr;
                }
                tails.insert(i-1);
            }
            else
            {
                bool extend_tail = false;
                if (auto t = tails.find(i-1); t != tails.end())
                {
                    states[i] = states[*t];
                    tails.erase(*t);
                    tails.insert(i);
                    extend_tail = true;
                }
                if (!extend_tail)
                    states[i] = ctr;
            }
        }

        std::cout << ctr << '\n';
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
    }
}

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (int i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}
std::string generate_sequence(unsigned length)
{
    auto gen = std::mt19937(std::random_device()());
    auto dis = std::uniform_int_distribution(0,1);

    auto s = std::stringstream();
    for (int i = 0; i < length; ++i)
    {
        s << dis(gen);
    }

    return s.str();
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    solve2();
    //int t; std::cin >> t;
    //auto input = get_input(t);
    //

    //auto input = std::vector<std::string>();
    //for (int i = 0; i < 1000; ++i)
    //{
    //    input.push_back(generate_sequence(40));
    //}

    //for (const auto& i : input)
    //{
    //    auto sol = solve3(i);

    //    if (validatee(i, sol))
    //    {
    //        //std::cout << i << '\n';
    //        //auto max = *std::max_element(sol.begin(),sol.end());
    //        //std::cout << max << '\n';
    //        //for (const auto& j : solve3(i))
    //        //{
    //        //    std::cout << j << ' ';
    //        //    //std::cout << j;
    //        //}
    //        //std::cout << '\n';
    //    }
    //    else
    //    {
    //        std::printf("validation failed:\nString:%2s %s\nStatuses:%1s", "", i.c_str(), "");
    //        for (auto i : sol)
    //        {
    //            std::cout << i;
    //        }
    //        std::cout << '\n';
    //    }
    //}
}


#include <bits/stdc++.h>

bool validatee(const std::string& s, const std::vector<int>& st)
{
    auto validate = std::vector<int>(st.size());

    bool valid = true;
    for (unsigned i = 0; i < st.size(); ++i)
    {
        if (validate[st[i]] == s[i])
        {
            std::printf("invalid: duplicate st[%d]=%d <-> s[%d]=%d\n",
                i, st[i], i, s[i]);
            valid = false;
        }
        validate[st[i]] = s[i];
    }
    return valid;
}

std::vector<int> solve(const std::string& s)
{
    // special case s = 1
    if (s.size() == 1)
    {
        std::cout << 1 << '\n' << 1 << '\n';
        return {1};
    }
    // special case s = 2
    if (s.size() == 2)
    {
        if (s[0] == s[1])
        {
            std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
            return {1,2};
        }
        else
        {
            std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
            return {1,1};
        }

    }

    // keep track of belongness to each subseq
    auto states = std::vector<int>(s.size());

    // keep track of tails
    auto tails = std::vector<int>();
    tails.reserve(s.size());

    int ctr=1;

    states[0] = 1;

    for (unsigned i = 1; i < s.size(); ++i)
    {
        if (s[i] == s[i-1])
        {
            bool fitting_tail=false;
            for (unsigned j = 0; j < tails.size(); ++j)
            {
                if (s[tails[j]] != s[i])
                {
                    states[i] = states[tails[j]];
                    tails[j] = i;
                    fitting_tail = true;
                    break;
                }
            }
            if (!fitting_tail)
            {
                //states[i-1] = ctr;
                //tails.push_back(i-1);
                states[i] = ++ctr;
            }
            if (auto res = std::find(tails.begin(),tails.end(), i-1); res != tails.end()
                    || tails.empty())
                tails.push_back(i-1);
        }
        else
        {
            bool extend_tail = false;
            for(unsigned j = 0; j < tails.size(); ++j)
            {
                if (tails[j] == i-1)
                {
                    states[i] = states[tails[j]];
                    tails[j] = i;
                    extend_tail = true;
                    break;
                }
            }
            if (!extend_tail)
                states[i] = ctr;
        }
    }

    return states;

    //std::cout << ctr << '\n';
    //for (auto i : states)
    //{
    //    std::cout << i << ' ';
    //}
    //std::cout << '\n';
}

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (int i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}
std::string generate_sequence(unsigned length)
{
    auto gen = std::mt19937(std::random_device()());
    auto dis = std::uniform_int_distribution(0,1);

    auto s = std::stringstream();
    for (int i = 0; i < length; ++i)
    {
        s << dis(gen);
    }

    return s.str();
}

int main()
{
    int t; std::cin >> t;
    auto input = get_input(t);

    //auto input = std::vector<std::string>();
    //for (unsigned i = 1; i <= 10000; ++i)
    //{
    //    auto s = generate_sequence(i);
    //    input.push_back(generate_sequence(20));
    //}
    //input.clear();
    //input.emplace_back("110011000");

    for (const auto& i : input)
    {
        auto sol = solve(i);

        if (validatee(i, sol) || true)
        {
            auto max = *std::max_element(sol.begin(),sol.end());
            std::cout << max << '\n';
            for (const auto& j : solve(i))
            {
                std::cout << j << ' ';
            }
            std::cout << '\n';
        }
        else
        {
            std::printf("validation failed:\nString:%2s %s\nStatuses:%1s", "", i.c_str(), "");
            for (auto i : sol)
            {
                std::cout << i;
            }
            std::cout << '\n';
        }
    }
}


#include <bits/stdc++.h>

bool validatee(const std::string& s, const std::vector<int>& st)
{
    auto validate = std::vector<int>(st.size());

    bool valid = true;
    for (unsigned i = 0; i < st.size(); ++i)
    {
        if (validate[st[i]] == s[i])
        {
            std::printf("invalid: duplicate st[%d]=%d <-> s[%d]=%d\n",
                i, st[i], i, s[i]);
            valid = false;
        }
        validate[st[i]] = s[i];
    }
    return valid;
}

std::vector<int> solve(const std::string& s)
{
    // special case s = 1
    if (s.size() == 1)
    {
        //std::cout << 1 << '\n' << 1 << '\n';
        return {1};
    }
    // special case s = 2
    if (s.size() == 2)
    {
        if (s[0] == s[1])
        {
            //std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
            return {1,2};
        }
        else
        {
            //std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
            return {1,1};
        }

    }

    // keep track of belongness to each subseq
    auto states = std::vector<int>(s.size());

    // keep track of tails
    auto tails = std::vector<int>();
    tails.reserve(s.size());

    int ctr=1;

    states[0] = 1;

    for (unsigned i = 1; i < s.size(); ++i)
    {
        if (s[i] == s[i-1])
        {
            bool fitting_tail=false;
            for (unsigned j = 0; j < tails.size(); ++j)
            {
                if (s[tails[j]] != s[i])
                {
                    states[i] = states[tails[j]];
                    tails[j] = i;
                    fitting_tail = true;
                    break;
                }
            }
            if (!fitting_tail)
            {
                states[i] = ++ctr;
            }
            if (auto res = std::find(tails.begin(),tails.end(), i-1); res == tails.end()
                    || tails.empty())
                tails.push_back(i-1);
        }
        else
        {
            bool extend_tail = false;
            for(unsigned j = 0; j < tails.size(); ++j)
            {
                if (tails[j] == i-1)
                {
                    states[i] = states[tails[j]];
                    tails[j] = i;
                    extend_tail = true;
                    break;
                }
            }
            if (!extend_tail)
                states[i] = ctr;
        }
    }

    return states;
}

void solve2()
{
    int t; std::cin >> t;
    while (t--)
    {
        int trash; std::cin >> trash;
        std::string s;
        std::cin >> s;

        // special case s = 1
        if (s.size() == 1)
        {
            std::cout << 1 << '\n' << 1 << '\n';
            //return {1};
        }
        // special case s = 2
        if (s.size() == 2)
        {
            if (s[0] == s[1])
            {
                std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
                //return {1,2};
            }
            else
            {
                std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
                //return {1,1};
            }

        }

        // keep track of belongness to each subseq
        auto states = std::vector<int>(s.size());

        // keep track of tails
        auto tails = std::vector<int>();
        tails.reserve(s.size());

        int ctr=1;

        states[0] = 1;

        for (unsigned i = 1; i < s.size(); ++i)
        {
            if (s[i] == s[i-1])
            {
                bool fitting_tail=false;
                for (unsigned j = 0; j < tails.size(); ++j)
                {
                    if (s[tails[j]] != s[i])
                    {
                        states[i] = states[tails[j]];
                        tails[j] = i;
                        fitting_tail = true;
                        break;
                    }
                }
                if (!fitting_tail)
                {
                    states[i] = ++ctr;
                }
                if (auto res = std::find(tails.begin(),tails.end(), i-1); res == tails.end()
                        || tails.empty())
                    tails.push_back(i-1);
            }
            else
            {
                bool extend_tail = false;
                for(unsigned j = 0; j < tails.size(); ++j)
                {
                    if (tails[j] == i-1)
                    {
                        states[i] = states[tails[j]];
                        tails[j] = i;
                        extend_tail = true;
                        break;
                    }
                }
                if (!extend_tail)
                    states[i] = ctr;
            }
        }

        std::cout << ctr << '\n';
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
    }
}

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (int i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}
std::string generate_sequence(unsigned length)
{
    auto gen = std::mt19937(std::random_device()());
    auto dis = std::uniform_int_distribution(0,1);

    auto s = std::stringstream();
    for (int i = 0; i < length; ++i)
    {
        s << dis(gen);
    }

    return s.str();
}

int main()
{
    solve2();
    //int t; std::cin >> t;
    //auto input = get_input(t);

    //for (const auto& i : input)
    //{
    //    auto sol = solve(i);

    //    if (true || validatee(i, sol))
    //    {
    //        //std::cout << i << '\n';
    //        auto max = *std::max_element(sol.begin(),sol.end());
    //        std::cout << max << '\n';
    //        for (const auto& j : solve(i))
    //        {
    //            std::cout << j << ' ';
    //            //std::cout << j;
    //        }
    //        std::cout << '\n';
    //    }
    //    else
    //    {
    //        std::printf("validation failed:\nString:%2s %s\nStatuses:%1s", "", i.c_str(), "");
    //        for (auto i : sol)
    //        {
    //            std::cout << i;
    //        }
    //        std::cout << '\n';
    //    }
    //}
}


#include <bits/stdc++.h>

bool validatee(const std::string& s, const std::vector<int>& st)
{
    auto validate = std::vector<int>(st.size());

    bool valid = true;
    for (unsigned i = 0; i < st.size(); ++i)
    {
        if (validate[st[i]] == s[i])
        {
            std::printf("invalid: duplicate st[%d]=%d <-> s[%d]=%d\n",
                i, st[i], i, s[i]);
            valid = false;
        }
        validate[st[i]] = s[i];
    }
    return valid;
}

//std::vector<int> solve(const std::string& s)
//{
//    // special case s = 1
//    if (s.size() == 1)
//    {
//        //std::cout << 1 << '\n' << 1 << '\n';
//        return {1};
//    }
//    // special case s = 2
//    if (s.size() == 2)
//    {
//        if (s[0] == s[1])
//        {
//            //std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
//            return {1,2};
//        }
//        else
//        {
//            //std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
//            return {1,1};
//        }
//
//    }
//
//    // keep track of belongness to each subseq
//    auto states = std::vector<int>(s.size());
//
//
//    // keep track of tails
//    auto tails = std::vector<int>();
//    tails.reserve(s.size());
//
//    int ctr=1;
//
//    states[0] = 1;
//
//    for (unsigned i = 1; i < s.size(); ++i)
//    {
//        if (s[i] == s[i-1])
//        {
//            bool fitting_tail=false;
//            for (unsigned j = 0; j < tails.size(); ++j)
//            {
//                if (s[tails.at(j)] != s[i])
//                {
//                    states[i] = states[tails.at(j)];
//                    tails[j] = i;
//                    fitting_tail = true;
//                    break;
//                }
//            }
//            if (!fitting_tail)
//            {
//                states[i] = ++ctr;
//            }
//            if (auto res = std::find(tails.begin(),tails.end(), i-1); res == tails.end()
//                    || tails.empty())
//                tails.push_back(i-1);
//        }
//        else
//        {
//            bool extend_tail = false;
//            for(unsigned j = 0; j < tails.size(); ++j)
//            {
//                if (tails.at(j) == i-1)
//                {
//                    states[i] = states[tails.at(j)];
//                    tails.at(j) = i;
//                    extend_tail = true;
//                    break;
//                }
//            }
//            if (!extend_tail)
//                states[i] = ctr;
//        }
//    }
//
//    return states;
//}

void solve2()
{
    int t; std::cin >> t;
    while (t--)
    {
        int trash; std::cin >> trash;
        std::string s;
        std::cin >> s;

        // special case s = 1
        if (s.size() == 1)
        {
            std::cout << 1 << '\n' << 1 << '\n';
            continue;
        }
        // special case s = 2
        if (s.size() == 2)
        {
            if (s[0] == s[1])
            {
                std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
                continue;
            }
            else
            {
                std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
                continue;
            }

        }

        // keep track of belongness to each subseq
        auto states = std::vector<int>(s.size());

        // keep track of tails
        //auto tails = std::vector<int>();
        //tails.reserve(s.size());
        auto tails = std::set<int>();

        int ctr=1;

        states[0] = 1;

        for (unsigned i = 1; i < s.size(); ++i)
        {
            if (s[i] == s[i-1])
            {
                bool fitting_tail=false;
                for (auto j = tails.begin(); j != tails.end(); ++j)
                {
                    if (s[*j] != s[i])
                    {
                        states[i] = states[*j];
                        //*j = i;
                        tails.erase(*j);
                        tails.insert(i);
                        fitting_tail = true;
                        break;
                    }
                }
                if (!fitting_tail)
                {
                    states[i] = ++ctr;
                }
                //if (auto res = std::find(tails.begin(),tails.end(), i-1); res == tails.end()
                //        || tails.empty())
                //    tails.push_back(i-1);
                //
                tails.insert(i-1);
            }
            else
            {
                bool extend_tail = false;
                for (auto j = tails.begin(); j != tails.end(); ++j)
                {
                    if (*j == i-1)
                    {
                        states[i] = states[*j];
                        //*j = i;
                        tails.erase(*j);
                        tails.insert(i);
                        extend_tail = true;
                        break;
                    }
                }
                if (!extend_tail)
                    states[i] = ctr;
            }
        }

        std::cout << ctr << '\n';
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
    }
}

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (int i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}
std::string generate_sequence(unsigned length)
{
    auto gen = std::mt19937(std::random_device()());
    auto dis = std::uniform_int_distribution(0,1);

    auto s = std::stringstream();
    for (int i = 0; i < length; ++i)
    {
        s << dis(gen);
    }

    return s.str();
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    solve2();
    //int t; std::cin >> t;
    //auto input = get_input(t);

    //for (const auto& i : input)
    //{
    //    auto sol = solve(i);

    //    if (true || validatee(i, sol))
    //    {
    //        //std::cout << i << '\n';
    //        auto max = *std::max_element(sol.begin(),sol.end());
    //        std::cout << max << '\n';
    //        for (const auto& j : solve(i))
    //        {
    //            std::cout << j << ' ';
    //            //std::cout << j;
    //        }
    //        std::cout << '\n';
    //    }
    //    else
    //    {
    //        std::printf("validation failed:\nString:%2s %s\nStatuses:%1s", "", i.c_str(), "");
    //        for (auto i : sol)
    //        {
    //            std::cout << i;
    //        }
    //        std::cout << '\n';
    //    }
    //}
}


#include <bits/stdc++.h>

int main()
{

    int t=0; std::cin >> t;
    while(t--)
    {
        int sz=0;
        std::cin>>sz;

        auto s = std::string();
        std::cin >> s;

        // special case s = 1
        if (s.size() == 1)
        {
            std::cout << 1 << '\n' << 1 << '\n';
            continue;
        }
        // special case s = 2
        if (s.size() == 2)
        {
            if (s[0] == s[1])
                std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
            else
                std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';

            continue;
        }

        auto states = std::vector<int>(s.size());
        for (auto& i : states)
            i = -5;

        int ctr=1;

        int tail = -1;
        states[0] = 1;

        for (unsigned i=1; i < s.size(); ++i)
        {
            if (s[i] == s[i-1])
            {
                if (tail == -1)
                {
                    tail = i-1;
                    states[i-1] = ctr;
                    states[i] = ++ctr;
                }
                else
                {
                    if (s[tail] == s[i])
                    {
                        tail = i-1;
                        states[i] = ++ctr;
                    }
                    else
                    {
                        states[i] = states[tail];
                        tail = i;
                    }
                }
            }
            else
            {
                states[i] = ctr;
            }
        }

        std::cout << ctr << '\n';
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
    }
}


#include <bits/stdc++.h>

bool validatee(const std::string& s, const std::vector<int>& st)
{
    auto validate = std::vector<int>(st.size());

    bool valid = true;
    for (unsigned i = 0; i < st.size(); ++i)
    {
        if (validate[st[i]] == s[i])
        {
            std::printf("invalid: duplicate st[%d]=%d <-> s[%d]=%d\n",
                i, st[i], i, s[i]);
            valid = false;
        }
        validate[st[i]] = s[i];
    }
    return valid;
}

bool retard_check(const std::string& s)
{
    for (int i = 1; i < s.size(); ++i)
    {
        if (s[i-1] != s[i])
            return false;
    }
    return true;
}

//std::vector<int> solve(const std::string& s)
//{
//    // special case s = 1
//    if (s.size() == 1)
//    {
//        //std::cout << 1 << '\n' << 1 << '\n';
//        return {1};
//    }
//    // special case s = 2
//    if (s.size() == 2)
//    {
//        if (s[0] == s[1])
//        {
//            //std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
//            return {1,2};
//        }
//        else
//        {
//            //std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
//            return {1,1};
//        }
//
//    }
//
//    // keep track of belongness to each subseq
//    auto states = std::vector<int>(s.size());
//
//
//    // keep track of tails
//    auto tails = std::vector<int>();
//    tails.reserve(s.size());
//
//    int ctr=1;
//
//    states[0] = 1;
//
//    for (unsigned i = 1; i < s.size(); ++i)
//    {
//        if (s[i] == s[i-1])
//        {
//            bool fitting_tail=false;
//            for (unsigned j = 0; j < tails.size(); ++j)
//            {
//                if (s[tails.at(j)] != s[i])
//                {
//                    states[i] = states[tails.at(j)];
//                    tails[j] = i;
//                    fitting_tail = true;
//                    break;
//                }
//            }
//            if (!fitting_tail)
//            {
//                states[i] = ++ctr;
//            }
//            if (auto res = std::find(tails.begin(),tails.end(), i-1); res == tails.end()
//                    || tails.empty())
//                tails.push_back(i-1);
//        }
//        else
//        {
//            bool extend_tail = false;
//            for(unsigned j = 0; j < tails.size(); ++j)
//            {
//                if (tails.at(j) == i-1)
//                {
//                    states[i] = states[tails.at(j)];
//                    tails.at(j) = i;
//                    extend_tail = true;
//                    break;
//                }
//            }
//            if (!extend_tail)
//                states[i] = ctr;
//        }
//    }
//
//    return states;
//}

std::vector<int> solve3(const std::string& s)
{
    // special case s = 1
    if (s.size() == 1)
    {
        //std::cout << 1 << '\n' << 1 << '\n';
        return {1};
    }
    // special case s = 2
    if (s.size() == 2)
    {
        if (s[0] == s[1])
        {
            //std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
            return {1,2};
        }
        else
        {
            //std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
            return {1,1};
        }

    }

    // keep track of belongness to each subseq
    auto states = std::vector<int>(s.size());

    // keep track of tails
    //auto tails = std::vector<int>();
    //tails.reserve(s.size());
    auto tails = std::set<int>();

    int ctr=1;

    states[0] = 1;

    for (unsigned i = 1; i < s.size(); ++i)
    {
        if (s[i] == s[i-1])
        {
            bool fitting_tail=false;
            for (auto j = tails.begin(); j != tails.end(); ++j)
            {
                if (s[*j] != s[i])
                {
                    states[i] = states[*j];
                    tails.erase(*j);
                    tails.insert(i);
                    fitting_tail = true;
                    break;
                }
            }
            if (!fitting_tail)
            {
                states[i] = ++ctr;
            }
            tails.insert(i-1);
        }
        //else
        //{
        //    bool extend_tail = false;
        //    for (auto j = tails.begin(); j != tails.end(); ++j)
        //    {
        //        if (*j == i-1)
        //        {
        //            states[i] = states[*j];
        //            tails.erase(i-1);
        //            tails.insert(i);
        //            extend_tail = true;
        //            break;
        //        }
        //    }
        //    if (!extend_tail)
        //        states[i] = ctr;
        //}
        else
        {
            bool extend_tail = false;
            if (auto j = tails.find(i-1); j != tails.end())
            {
                states[i] = states[*j];
                tails.erase(i-1);
                tails.insert(i);
                extend_tail = true;
            }
            if (!extend_tail)
                states[i] = ctr;
        }
    }
    return states;
}

void solve2()
{
    int t; std::cin >> t;
    while (t--)
    {
        int trash; std::cin >> trash;
        std::string s;
        std::cin >> s;

        // special case s = 1
        if (s.size() == 1)
        {
            std::cout << 1 << '\n' << 1 << '\n';
            continue;
        }
        // special case s = 2
        if (s.size() == 2)
        {
            if (s[0] == s[1])
            {
                std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
                continue;
            }
            else
            {
                std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
                continue;
            }

        }

        // retard check
        if (retard_check(s))
        {
            std::cout << s.size() << '\n';
            for (int i = 1; i <= s.size(); ++i)
            {
                std::cout << i << ' ';
            }
            std::cout << '\n';
            continue;
        }

        // keep track of belongness to each subseq
        auto states = std::vector<int>(s.size());

        // keep track of tails
        //auto tails = std::vector<int>();
        //tails.reserve(s.size());
        auto tails = std::set<int>();

        int ctr=1;

        states[0] = 1;

        for (unsigned i = 1; i < s.size(); ++i)
        {
            if (s[i] == s[i-1])
            {
                bool fitting_tail=false;
                for (auto j = tails.begin(); j != tails.end(); ++j)
                {
                    if (s[*j] != s[i])
                    {
                        states[i] = states[*j];
                        //*j = i;
                        tails.erase(*j);
                        tails.insert(i);
                        fitting_tail = true;
                        break;
                    }
                }
                if (!fitting_tail)
                {
                    states[i] = ++ctr;
                }
                tails.insert(i-1);
            }
            else
            {
                bool extend_tail = false;
                if (auto t = tails.find(i-1); t != tails.end())
                {
                    states[i] = states[*t];
                    tails.erase(*t);
                    tails.insert(i);
                    extend_tail = true;
                }
                if (!extend_tail)
                    states[i] = ctr;
            }
        }

        std::cout << ctr << '\n';
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
    }
}

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (int i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}
std::string generate_sequence(unsigned length)
{
    auto gen = std::mt19937(std::random_device()());
    auto dis = std::uniform_int_distribution(0,1);

    auto s = std::stringstream();
    for (int i = 0; i < length; ++i)
    {
        s << dis(gen);
    }

    return s.str();
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    solve2();
    //int t; std::cin >> t;
    //auto input = get_input(t);
    //

    //auto input = std::vector<std::string>();
    //for (int i = 0; i < 1000; ++i)
    //{
    //    input.push_back(generate_sequence(40));
    //}

    //for (const auto& i : input)
    //{
    //    auto sol = solve3(i);

    //    if (validatee(i, sol))
    //    {
    //        //std::cout << i << '\n';
    //        //auto max = *std::max_element(sol.begin(),sol.end());
    //        //std::cout << max << '\n';
    //        //for (const auto& j : solve3(i))
    //        //{
    //        //    std::cout << j << ' ';
    //        //    //std::cout << j;
    //        //}
    //        //std::cout << '\n';
    //    }
    //    else
    //    {
    //        std::printf("validation failed:\nString:%2s %s\nStatuses:%1s", "", i.c_str(), "");
    //        for (auto i : sol)
    //        {
    //            std::cout << i;
    //        }
    //        std::cout << '\n';
    //    }
    //}
}


#include <bits/stdc++.h>

bool validate(const std::string& s, const std::vector<int>& st)
{
    auto validate = std::vector<int>(st.size());

    bool valid = true;
    for (unsigned i = 0; i < st.size(); ++i)
    {
        if (validate[st[i]] == s[i])
        {
            std::printf("invalid: duplicate st[%d]=%d <-> s[%d]=%d\n",
                i, st[i], i, s[i]);
            valid = false;
        }
        validate[st[i]] = s[i];
    }
    return valid;
}

int main()
{

    int t=0; std::cin >> t;
    while(t--)
    {
        int sz=0;
        std::cin>>sz;

        auto s = std::string();
        std::cin >> s;

        // special case s = 1
        if (s.size() == 1)
        {
            std::cout << 1 << '\n' << 1 << '\n';
            continue;
        }
        // special case s = 2
        if (s.size() == 2)
        {
            if (s[0] == s[1])
                std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
            else
                std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';

            continue;
        }

        // keep track of belongness to each subseq
        auto states = std::vector<int>(s.size());

        // keep track of tails
        auto tails = std::vector<int>();
        tails.reserve(s.size());

        int ctr=1;

        states[0] = 1;

        for (unsigned i = 1; i < s.size(); ++i)
        {
            if (s[i] == s[i-1])
            {
                bool fitting_tail=false;
                for (unsigned j = 0; j < tails.size(); ++j)
                {
                    if (s[tails[j]] != s[i])
                    {
                        states[i] = states[tails[j]];
                        tails[j] = i;
                        fitting_tail = true;
                        break;
                    }
                }
                if (!fitting_tail)
                {
                    tails.push_back(i-1);

                    //states[i-1] = ctr;
                    states[i] = ++ctr;
                }
            }
            else
            {
                bool extend_tail = false;
                for(unsigned j = 0; j < tails.size(); ++j)
                {
                    if (tails[j] == i-1)
                    {
                        states[i] = states[tails[j]];
                        tails[j] = i;
                        extend_tail = true;
                        break;
                    }
                }
                if (!extend_tail)
                    states[i] = ctr;
            }
        }

        std::cout << ctr << '\n';
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
    }
}

//        auto states = std::vector<int>(s.size());
//        for (auto& i : states)
//            i = -5;
//
//        auto tails = std::set<int>();
//        for (auto& i : tails)
//            i = -5;
//
//        int ctr=1;
//
//        int tail = -1;
//        states[0] = 1;
//
//        for (unsigned i=1; i < s.size(); ++i)
//        {
//            if (s[i] == s[i-1])
//            {
//                if (tail == -1)
//                {
//                    tails.insert(i-1);
//                    //tail = i-1;
//                    states[i-1] = ctr;
//                    states[i] = ++ctr;
//                }
//                else
//                {
//                    if (s[tail] == s[i])
//                    {
//                        //tail = i-1;
//                        tails.insert(i-1);
//                        states[i] = ++ctr;
//                    }
//                    else
//                    {
//                        states[i] = states[tail];
//                        tail = i;
//                    }
//                }
//            }
//            else
//            {
//                states[i] = ctr;
//            }
//        }
//
//        std::cout << ctr << '\n';
//        for (auto i : states)
//        {
//            std::cout << i << ' ';
//        }
//        std::cout << '\n';


#include <bits/stdc++.h>

using i = std::int64_t;
using u = std::uint64_t;

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (unsigned i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}

std::string generate_sequence(unsigned length)
{
    auto gen = std::mt19937(std::random_device()());
    auto dis = std::uniform_int_distribution(0,1);

    auto s = std::stringstream();
    for (unsigned i = 0; i < length; ++i)
    {
        s << dis(gen);
    }

    return s.str();
}

std::vector<int> sol(std::string_view s)
{
    auto states = std::vector<int>(s.size());

    auto s0 = std::stack<int>();
    auto s1 = std::stack<int>();

    s0.push(0);
    s1.push(0);

    unsigned ctr = 0;

    for (size_t i=0; i < s.size(); ++i)
    {
        if (s[i] == '0')
        {
            if (s1.size() > 1)
            {
                states[i] = s1.top();
                s1.pop();
                s0.push(states[i]);
            }
            else
            {
                ++ctr;
                s0.push(s1.size() + s0.size() -1);
                states[i] = s0.top();
            }
        }
        else
        {
            if (s0.size() > 1)
            {
                states[i] = s0.top();
                s0.pop();
                s1.push(states[i]);
            }
            else
            {
                ++ctr;
                s1.push(s1.size() + s0.size() -1);
                states[i] = s1.top();
            }
        }
    }
    std::cout << s0.size() + s1.size()-2 << '\n';
    return states;
}

//bool validate(std::string_view s, const std::vector<int>& states)
//{
//    auto checkmap = std::unordered_map<int, char>();
//    for (unsigned i = 0; i < s.size(); ++i)
//    {
//        if (checkmap.contains(states[i]))
//        {
//            if (checkmap[states[i]] == s[i])
//            {
//                std::cout << "INVALID:\n";
//                return false;
//            }
//            else
//                checkmap[states[i]] = s[i];
//        }
//        else
//            checkmap[states[i]] = s[i];
//    }
//    return true;
//}

int main()
{
    int t = 0; std::cin >> t;
    auto input = get_input(t);
    //auto input = std::vector<std::string>();

    //for (int i = 0; i < 1000; ++i)
    //{
    //    input.push_back(generate_sequence(1000));
    //}
    ////input = {"111000"};
    for (std::string_view s : input) {
        auto states = sol(s);
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
        ////s = "100";
        ////states = {1,1,1};
        //if (!validate(s, states))
        //{
        //    for (const auto c : s)
        //    {
        //        std::cout << c << ' ';
        //    }
        //    std::cout << '\n';
        //    for (const auto i : states)
        //    {
        //        std::cout << i << ' ';
        //    }
        //    std::cout << '\n';
        //}
    }
}


#include <bits/stdc++.h>

bool validatee(const std::string& s, const std::vector<int>& st)
{
    auto validate = std::vector<int>(st.size());

    bool valid = true;
    for (unsigned i = 0; i < st.size(); ++i)
    {
        if (validate[st[i]] == s[i])
        {
            std::printf("invalid: duplicate st[%d]=%d <-> s[%d]=%d\n",
                i, st[i], i, s[i]);
            valid = false;
        }
        validate[st[i]] = s[i];
    }
    return valid;
}

std::vector<int> solve(const std::string& s)
{
    // special case s = 1
    if (s.size() == 1)
    {
        //std::cout << 1 << '\n' << 1 << '\n';
        return {1};
    }
    // special case s = 2
    if (s.size() == 2)
    {
        if (s[0] == s[1])
        {
            //std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
            return {1,2};
        }
        else
        {
            //std::cout << 1 << '\n' << 1  << ' ' << 1 << '\n';
            return {1,1};
        }

    }

    // keep track of belongness to each subseq
    auto states = std::vector<int>(s.size());

    // keep track of tails
    auto tails = std::vector<int>();
    tails.reserve(s.size());

    int ctr=1;

    states[0] = 1;

    for (unsigned i = 1; i < s.size(); ++i)
    {
        if (s[i] == s[i-1])
        {
            bool fitting_tail=false;
            for (unsigned j = 0; j < tails.size(); ++j)
            {
                if (s[tails[j]] != s[i])
                {
                    states[i] = states[tails[j]];
                    tails[j] = i;
                    fitting_tail = true;
                    break;
                }
            }
            if (!fitting_tail)
            {
                states[i] = ++ctr;
            }
            if (auto res = std::find(tails.begin(),tails.end(), i-1); res == tails.end()
                    || tails.empty())
                tails.push_back(i-1);
        }
        else
        {
            bool extend_tail = false;
            for(unsigned j = 0; j < tails.size(); ++j)
            {
                if (tails[j] == i-1)
                {
                    states[i] = states[tails[j]];
                    tails[j] = i;
                    extend_tail = true;
                    break;
                }
            }
            if (!extend_tail)
                states[i] = ctr;
        }
    }

    return states;

    //std::cout << ctr << '\n';
    //for (auto i : states)
    //{
    //    std::cout << i << ' ';
    //}
    //std::cout << '\n';
}

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (int i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}
std::string generate_sequence(unsigned length)
{
    auto gen = std::mt19937(std::random_device()());
    auto dis = std::uniform_int_distribution(0,1);

    auto s = std::stringstream();
    for (int i = 0; i < length; ++i)
    {
        s << dis(gen);
    }

    return s.str();
}

int main()
{
    int t; std::cin >> t;
    auto input = get_input(t);

    //auto input = std::vector<std::string>();
    //for (unsigned i = 1; i <= 10000; ++i)
    //{
    //    auto s = generate_sequence(i);
    //    input.push_back(generate_sequence(20));
    //}
    //input.clear();
    //input.emplace_back("110011000110101010101001010010010000101111100101010101010110101010");
    //input.emplace_back("1100110");

    for (const auto& i : input)
    {
        auto sol = solve(i);

        if (true || validatee(i, sol))
        {
            //std::cout << i << '\n';
            auto max = *std::max_element(sol.begin(),sol.end());
            std::cout << max << '\n';
            for (const auto& j : solve(i))
            {
                std::cout << j << ' ';
                //std::cout << j;
            }
            std::cout << '\n';
        }
        else
        {
            std::printf("validation failed:\nString:%2s %s\nStatuses:%1s", "", i.c_str(), "");
            for (auto i : sol)
            {
                std::cout << i;
            }
            std::cout << '\n';
        }
    }
}


#include <bits/stdc++.h>

using i = std::int64_t;
using u = std::uint64_t;

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (unsigned i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}

std::vector<int> sol(std::string_view s)
{
    auto states = std::vector<int>(s.size());

    auto s0 = std::stack<int>();
    auto s1 = std::stack<int>();

    s0.push(0);
    s1.push(0);

    for (size_t i=0; i < s.size(); ++i)
    {
        if (s[i] == '0')
        {
            if (s1.size() > 1)
            {
                states[i] = s1.top();
                s1.pop();
                s0.push(states[i]);
            }
            else
            {
                s0.push(s1.size() + s0.size() -1);
                states[i] = s0.top();
            }
        }
        else
        {
            if (s0.size() > 1)
            {
                states[i] = s0.top();
                s0.pop();
                s1.push(states[i]);
            }
            else
            {
                s1.push(s1.size() + s0.size() -1);
                states[i] = s1.top();
            }
        }
    }
    std::cout << s0.size() + s1.size()-2 << '\n';
    return states;
}

int main()
{
    int t = 0; std::cin >> t;
    auto input = get_input(t);

    for (std::string_view s : input) {
        auto states = sol(s);
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
    }
}


#include <bits/stdc++.h>

using i = std::int64_t;
using u = std::uint64_t;

std::vector<std::string> get_input(unsigned t)
{
    auto input = std::vector<std::string>(t);

    for (unsigned i=0; i<t; ++i)
    {
        auto tmp = std::string();

        int trash;
        std::cin>>trash;

        auto s = std::string();
        std::cin >> s;

        input[i] = s;
    }

    return input;
}

std::string generate_sequence(unsigned length)
{
    auto gen = std::mt19937(std::random_device()());
    auto dis = std::uniform_int_distribution(0,1);

    auto s = std::stringstream();
    for (unsigned i = 0; i < length; ++i)
    {
        s << dis(gen);
    }

    return s.str();
}

std::vector<int> sol(std::string_view s)
{
    auto states = std::vector<int>(s.size());

    auto s0 = std::stack<int>();
    auto s1 = std::stack<int>();

    s0.push(0);
    s1.push(0);

    unsigned ctr = 0;

    for (size_t i=0; i < s.size(); ++i)
    {
        if (s[i] == '0')
        {
            if (s1.size() > 1)
            {
                states[i] = s1.top();
                s1.pop();
                s0.push(states[i]);
            }
            else
            {
                ++ctr;
                s0.push(s1.size() + s0.size() -1);
                states[i] = s0.top();
            }
        }
        else
        {
            if (s0.size() > 1)
            {
                states[i] = s0.top();
                s0.pop();
                s1.push(states[i]);
            }
            else
            {
                ++ctr;
                s1.push(s1.size() + s0.size() -1);
                states[i] = s1.top();
            }
        }
    }
    std::cout << s0.size() + s1.size()-2 << '\n';
    return states;
}

bool validate(std::string_view s, const std::vector<int>& states)
{
    auto checkmap = std::unordered_map<int, char>();
    for (unsigned i = 0; i < s.size(); ++i)
    {
        if (checkmap.contains(states[i]))
        {
            if (checkmap[states[i]] == s[i])
            {
                std::cout << "INVALID:\n";
                return false;
            }
            else
                checkmap[states[i]] = s[i];
        }
        else
            checkmap[states[i]] = s[i];
    }
    return true;
}

int main()
{
    int t = 0; std::cin >> t;
    auto input = get_input(t);
    //auto input = std::vector<std::string>();

    //for (int i = 0; i < 1000; ++i)
    //{
    //    input.push_back(generate_sequence(1000));
    //}
    ////input = {"111000"};
    for (std::string_view s : input) {
        auto states = sol(s);
        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
        ////s = "100";
        ////states = {1,1,1};
        //if (!validate(s, states))
        //{
        //    for (const auto c : s)
        //    {
        //        std::cout << c << ' ';
        //    }
        //    std::cout << '\n';
        //    for (const auto i : states)
        //    {
        //        std::cout << i << ' ';
        //    }
        //    std::cout << '\n';
        //}
    }
}


#include <bits/stdc++.h>

int main()
{

    int t=0; std::cin >> t;
    while(t--)
    {
        int sz=0;
        std::cin>>sz;

        auto s = std::string();
        std::cin >> s;

        // special case s = 1
        if (s.size() == 1)
        {
            std::cout << 1 << '\n' << 1 << '\n';
            continue;
        }
        // special case s = 2
        if (s.size() == 2)
        {
            if (s[0] == s[1])
                std::cout << 2 << '\n' << 1 << ' ' << 2 << '\n';
            else
                std::cout << 1 << '\n' << 1 << '\n';

            continue;
        }

        auto states = std::vector<int>(s.size());
        for (auto& i : states)
            i = -5;

        int ctr=1;

        int tail = -1;
        states[0] = 1;

        for (unsigned i=1; i < s.size(); ++i)
        {
            if (s[i] == s[i-1])
            {
                if (tail == -1)
                {
                    tail = i-1;
                    states[i-1] = ctr;
                    states[i] = ++ctr;
                }
                else
                {
                    if (s[tail] == s[i])
                    {
                        tail = i-1;
                        states[i] = ++ctr;
                    }
                    else
                    {
                        states[i] = states[tail];
                        tail = i;
                    }
                }
            }
            else
            {
                states[i] = ctr;
            }
        }

        for (auto i : states)
        {
            std::cout << i << ' ';
        }
        std::cout << '\n';
        std::cout << ctr << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
//#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0;i<n;i++)
#define per(n)           for(int i=n;i>-1;i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
    int res = 1;

    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int32_t main(){
  freopen("in.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int t;
  cin>>t;
  while(t--){
int n;
cin>>n;
string s;
cin>>s;
set<int>o,z;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='1')
  o.insert(i);
  else
  z.insert(i);
}
int curr=1;
while(o.size()>0||z.size()>0){
  if(o.size()>z.size()||(o.size()==z.size()&&*o.begin()<*z.begin())){
    if(o.size()==0)
    break;
    auto it=o.begin();
    int x=*it;
    ans[x]=curr;
    o.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=o.upper_bound(x);
        if(y==o.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
  else{
    if(z.size()==0)
    break;
    auto it=z.begin();
    int x=*it;
    z.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=o.upper_bound(x);
        if(y==o.end()){
        if(ans[x]==0)
        ans[x]=curr;
      curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
}
cout<<--curr<<endl;
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0;i<n;i++)
#define per(n)           for(int i=n;i>-1;i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
    int res = 1;

    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int32_t main(){
  FAST;
  int t;
  cin>>t;
  while(t--){
int n;
cin>>n;
string s;
cin>>s;
set<int>o,z;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='1')
  o.insert(i);
  else
  z.insert(i);
}
int curr=1;
while(o.size()||z.size()){
  if(o.size()>z.size()||(o.size()==z.size()&&*o.begin()<*z.begin())){
    auto it=o.begin();
    int x=*it;
    ans[x]=curr;
    o.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=o.upper_bound(x);
        if(y==o.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
  else{
    auto it=z.begin();
    int x=*it;
    z.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=o.upper_bound(x);
        if(y==o.end()){
        if(ans[x]==0)
        ans[x]=curr;
      curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
}
cout<<--curr<<endl;
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0;i<n;i++)
#define per(n)           for(int i=n;i>-1;i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
    int res = 1;

    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int32_t main(){
  FAST;
  int t;
  cin>>t;
  while(t--){
int n;
cin>>n;
string s;
cin>>s;
set<int>o,z;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='1')
  o.insert(i);
  else
  z.insert(i);
}
int curr=1;
while(o.size()||z.size()){
  if(o.size()>z.size()){
    auto it=o.begin();
    int x=*it;
    ans[x]=curr;
    o.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=o.upper_bound(x);
        if(y==o.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
  else{
    auto it=z.begin();
    int x=*it;
    z.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=o.upper_bound(x);
        if(y==o.end()){
        if(ans[x]==0)
        ans[x]=curr;
      curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
}
cout<<--curr<<endl;
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0;i<n;i++)
#define per(n)           for(int i=n;i>-1;i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
    int res = 1;

    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int32_t main(){
  int t;
  cin>>t;
  while(t--){
int n;
cin>>n;
string s;
cin>>s;
set<int>o,z;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='1')
  o.insert(i);
  else
  z.insert(i);
}
int curr=1;
while(o.size()>0||z.size()>0){
  if(o.size()>z.size()||(o.size()==z.size()&&*o.begin()<*z.begin())){
    auto it=o.begin();
    int x=*it;
    ans[x]=curr;
    o.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=o.upper_bound(x);
        if(y==o.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
  else{
    auto it=z.begin();
    int x=*it;
    z.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=o.upper_bound(x);
        if(y==o.end()){
        if(ans[x]==0)
        ans[x]=curr;
      curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
}
cout<<--curr<<endl;
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0;i<n;i++)
#define per(n)           for(int i=n;i>-1;i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
    int res = 1;

    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int32_t main(){
  FAST;
  int t;
  cin>>t;
  while(t--){
int n;
cin>>n;
string s;
cin>>s;
set<int>o,z;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='1')
  o.insert(i);
  else
  z.insert(i);
}
int curr=1;
while(o.size()||z.size()){
  if(o.size()>z.size()||(o.size()==z.size()&&o.size()!=0&&*o.begin()<*z.begin())){
    auto it=o.begin();
    int x=*it;
    ans[x]=curr;
    o.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=o.upper_bound(x);
        if(y==o.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
  else{
    auto it=z.begin();
    int x=*it;
    z.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=o.upper_bound(x);
        if(y==o.end()){
        if(ans[x]==0)
        ans[x]=curr;
      curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
}
cout<<--curr<<endl;
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e9
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0; i<n; i++)
#define per(n)           for(int i=n; i>-1; i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
        int res = 1;

        while (y > 0) {
                if (y & 1)
                        res = ((res%mod)*(x%mod));
                y = y >> 1;
                x = x * x;
        }
        return res;
}

int32_t main(){
FAST;
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
vi z,o;
int curr=1;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='0'){
    if(o.size()==0){
      z.pb(curr);
      ans[i]=curr;
      curr++;
    }
  else{
    ans[i]=o.back();
    o.pop_back();
    z.pb(ans[i]);
  }
  }
else{
  if(z.size()==0){
    o.pb(curr);
    ans[i]=curr;
    curr++;
  }
else{
  ans[i]=z.back();
  z.pop_back();
  o.pb(ans[i]);
}
}
}
cout<<*max_element(all(ans))<<endl;
for(auto i:ans)
cout<<i<<" ";
cout<<endl;
}
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
//#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0;i<n;i++)
#define per(n)           for(int i=n;i>-1;i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
    int res = 1;

    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int32_t main(){
  int t;
  cin>>t;
  while(t--){
int n;
cin>>n;
string s;
cin>>s;
set<int>o,z;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='1')
  o.insert(i);
  else
  z.insert(i);
}
int curr=1;
while(o.size()>0||z.size()>0){
  if(o.size()>z.size()||(o.size()==z.size()&&*o.begin()<*z.begin())){
    if(o.size()==0)
    break;
    auto it=o.begin();
    int x=*it;
    ans[x]=curr;
    o.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=o.upper_bound(x);
        if(y==o.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
  else{
    if(z.size()==0)
    break;
    auto it=z.begin();
    int x=*it;
    z.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=o.upper_bound(x);
        if(y==o.end()){
        if(ans[x]==0)
        ans[x]=curr;
      curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
}
cout<<--curr<<endl;
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e9
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0; i<n; i++)
#define per(n)           for(int i=n; i>-1; i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
        int res = 1;

        while (y > 0) {
                if (y & 1)
                        res = ((res%mod)*(x%mod));
                y = y >> 1;
                x = x * x;
        }
        return res;
}

int32_t main(){
FAST;
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
vi z,o;
int curr=1;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='0'){
    if(o.size()==0){
      z.pb(curr);
      ans[i]=curr;
      curr++;
    }
  else{
    ans[i]=o.back();
    o.pop_back();
    z.pb(ans[i]);
  }
  }
else{
  if(z.size()==0){
    o.pb(curr);
    ans[i]=curr;
    curr++;
  }
else{
  ans[i]=z.back();
  z.pop_back();
  o.pb(ans[i]);
}
}
}
for(auto i:ans)
cout<<i<<" ";
cout<<endl;
}
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(v)          (v).begin(),(v).end()
#define allr(v)         (v).rbegin(),(v).rend()
#define ff              first
#define ss              second
#define int           long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define mod             1000000007
#define sp(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define deb(x)          cout<<"["<<#x<<"="<<x<<"]"<<endl
#define endl            '\n'
#define FAST             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(n)           for(int i=0;i<n;i++)
#define per(n)           for(int i=n;i>-1;i--)
#define set_bits(x)        __builtin_popcount(x)
int power(int x, int y)
{
    int res = 1;

    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int32_t main(){
  FAST;
  int t;
  cin>>t;
  while(t--){
int n;
cin>>n;
string s;
cin>>s;
set<int>o,z;
vi ans(n);
for(int i=0;i<n;i++){
  if(s[i]=='1')
  o.insert(i);
  else
  z.insert(i);
}
int curr=1;
while(o.size()||z.size()){
  if(o.size()>z.size()){
    auto it=o.begin();
    int x=*it;
    ans[x]=curr;
    o.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=o.upper_bound(x);
        if(y==o.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
  else{
    auto it=z.begin();
    int x=*it;
    z.erase(it);
    bool f=true;
    while(true){
      if(f){
        auto y=o.upper_bound(x);
        if(y==o.end()){
        if(ans[x]==0)
        ans[x]=curr;
      curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        o.erase(y);
        x=*y;
        f=false;
      }
      }
      else{
        auto y=z.upper_bound(x);
        if(y==z.end()){
          if(ans[x]==0)
          ans[x]=curr;
          curr++;
        break;
      }
      else{
        ans[*y]=curr;
        ans[x]=curr;
        z.erase(y);
        x=*y;
        f=true;
      }
      }
    }
  }
}
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}


#include <bits/stdc++.h>

std::vector<char> a;
std::vector<int> out;

int id;
int n;
int max;

void process(int pos)
{
	++id;
	if(id > max) max = id;
	char cur = a[pos];
	a[pos] = 'a';
	out[pos] = id;
	++pos;
	int count{1};
	while(pos < n)
	{
		if(a[pos] != 'a')
		{
			if(a[pos] == cur)
			{
				if(count&1 || id == 1)process(pos);
				else
				{
					--id;
					return;
				}
			}
			else
			{
				if(cur == '1') cur = '0';
				else cur = '1';
				out[pos] = id;
				a[cur] = 'a';
				++count;
			}
		}
		++pos;
	}
	--id;
}

int main()
{
    int t;
    scanf("%i", &t);
    while(t--)
    {
		scanf("%i", &n);

		a.resize(n);
		out.resize(n);
		id = 0;
		max = 0;

		scanf("%s", &a[0]);

		process(0);
		printf("%i\n", max);
		for(int i{}; i < n; ++i)
		{
			printf("%i ", out[i]);
		}
		putchar('\n');
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
    int t;
    std::cin >> t;
    while(t--)
    {
        int n;
        std::cin >> n;
        int count = n;
        int layer = 0;
        std::string a(' ', n);
        std::vector<int> out(n);
        std::cin >> a;
        char last{0};
        while(count > 0)
        {
            last = 0;
            ++layer;
            for(int i{}; i < n; ++i)
            {
                if (a[i] != 0)
                    if (last != 0)
                    {
                        if(a[i] != last)
                        {
                            --count;
                            last = a[i];
                            a[i] = 0;
                            out[i] = layer;
                        }
                    }
                    else
                    {
                        last = a[i];
                        a[i] = 0;
                        out[i] = layer;
                        --count;
                    }

            }
        }
        std::cout << layer << '\n';
        for(int i{}; i<n; ++i) std::cout << out[i] << ' ';
        std::cout << '\n';
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
	std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    int t;
    std::cin >> t;
    while(t--)
    {
        int n;
        std::cin >> n;
        int count = n;
        int layer = 0;
        std::string a(' ', n);
        std::vector<int> out(n);
        std::cin >> a;
        char last{0};
        while(count > 0)
        {
            last = 0;
            ++layer;
            for(int i{}; i < n; ++i)
            {
                if (a[i] != 0)
                    if (last != 0)
                    {
                        if(a[i] != last)
                        {
                            --count;
                            last = a[i];
                            a[i] = 0;
                            out[i] = layer;
                        }
                    }
                    else
                    {
                        last = a[i];
                        a[i] = 0;
                        out[i] = layer;
                        --count;
                    }

            }
        }
        std::cout << layer << '\n';
        for(int i{}; i<n; ++i) std::cout << out[i] << ' ';
        std::cout << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int t;
	scanf("%i", &t);
	for (int i = 0; i < t; ++i)
	{
		int n;
		scanf("%i", &n);
		getchar();
		vector<bool> a(n);
		vector<int> out(n);
		stack<int> sk[2]{};
		int sz{};
		for (int i = 0; i < n; ++i)
			a[i] = (getchar() == '1');
		getchar();
		for (int i = 0; i < n; ++i)
		{
			bool b = a[i];
			if(sk[b].empty())
			{
				++sz;
				sk[!b].push(sz);
				out[i] = sz;
			}
			else
			{
				out[i] = sk[b].top();
				sk[!b].push(sk[b].top());
				sk[b].pop();
			}
		}
		printf("%i\n", sz);
		for (int i = 0; i < n; ++i)
			printf("%i ", out[i]);
		putchar('\n');
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
    int t;
    std::cin >> t;
    while(t--)
    {
        int n;
        int count{1};
        int max{1};
        std::cin >> n;
        std::string a(' ', n);
        std::vector<int> out(n);
        std::cin >> a;
        char last{0};
        out[0] = 1;
        for(int i{1}; i < n; ++i)
        {
            if(a[i] == a[i-1])
            {
                ++count;
                out[i] = count;
                if(count > max) max = out[i];
            }
            else
            {
                count = 1;
                out[i] = 1;
            }
        }
        std::cout << max << '\n';
        for(int i{}; i<n; ++i) std::cout << out[i] << ' ';
        std::cout << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

std::vector<char> a;
std::vector<int> out;

int id;
int n;
int max;

void process(int pos)
{
	++id;
	if(id > max) max = id;
	char cur = a[pos];
	a[pos] = 'a';
	out[pos] = id;
	++pos;
	int count{1};
	while(pos < n)
	{
		if(a[pos] != 'a')
		{
			if(a[pos] == cur)
			{
				if((count&1) || id == 1)process(pos);
				else
				{
					--id;
					return;
				}
			}
			else
			{
				if(cur == '1') cur = '0';
				else cur = '1';
				out[pos] = id;
				a[pos] = 'a';
				++count;
			}
		}
		++pos;
	}
	--id;
}

int main()
{
    int t;
    scanf("%i", &t);
    while(t--)
    {
		scanf("%i", &n);

		a.resize(n);
		out.resize(n);
		id = 0;
		max = 0;

		scanf("%s", &a[0]);

		process(0);
		printf("%i\n", max);
		for(int i{}; i < n; ++i)
		{
			printf("%i ", out[i]);
		}
		putchar('\n');
	}
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int t;
	scanf("%i", &t);
	for (int i = 0; i < t; ++i)
	{
		int n;
		scanf("%i", &n);
		getchar();
		vector<bool> a(n);
		vector<int> out(n);
		vector<bool> st;
		st.reserve(n);
		for (int i = 0; i < n; ++i)
			a[i] = (getchar() == '1');
		getchar();
		for (int i = 0; i < n; ++i)
		{
			auto it = find(st.begin(), st.end(), !a[i]);
			out[i] = it - st.begin() + 1;
			if(it == st.end())
				st.push_back(a[i]);
			else *it = a[i];

		}
		printf("%i\n", (int)st.size());
		for (int i = 0; i < n; ++i)
			printf("%i ", out[i]);
		putchar('\n');
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
    int t;
    std::cin >> t;
    while(t--)
    {
        int n;
        int count{1};
        int count0{};
        int count1{};
        int max{1};
        std::cin >> n;
        std::string a(' ', n);
        std::vector<int> out(n);
        std::cin >> a;
        out[0] = 1;
        if(a[0] == '1') ++count1;
        else ++count0;
        for(int i{1}; i < n; ++i)
        {
            if(a[i] == '0')
            {
                ++count0;
                --count1;
            }
            else
            {
                --count0;
                ++count1;
            }
            if(count0 >= 0&& count1 >=0)
                if (a[i] == a[i - 1])
                {
                    ++count;
                    out[i] = count;
                    if (count > max)
                        max = out[i];
                }
                else
                {
                    count = 1;
                    out[i] = 1;
                }
            else
            {
                if(count0 < 0)
                {
                    out[i] = count1;
                    ++count0;
                }
                else
                {
                    out[i] = count0;
                    ++count1;
                }
            }

        }
        std::cout << count0 + count1 << '\n';
        for(int i{}; i<n; ++i) std::cout << out[i] << ' ';
        std::cout << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int t;
	scanf("%i", &t);
	for (int i = 0; i < t; ++i)
	{
		int n;
		scanf("%i", &n);
		getchar();
		vector<bool> a(n);
		vector<int> out(n);
		vector<bool> st;
		st.reserve(n);
		for (int i = 0; i < n; ++i)
			a[i] = (getchar() == '1');
		getchar();
		for (int i = 0; i < n; ++i)
		{
			auto it = find(st.begin(), st.end(), !a[i]);
			out[i] = it - st.begin() + 1;
			if(it == st.end())
				st.push_back(a[i]);
			else *it = a[i];

		}
		printf("%lli\n", st.size());
		for (int i = 0; i < n; ++i)
			printf("%i ", out[i]);
		putchar('\n');
	}
}


#include <bits/stdc++.h>

std::vector<char> a;
std::vector<int> out;

int id{};
int n{};
int max{};

void process(int pos)
{
	++id;
	if(id > max) max = id;
	char cur = a[pos];
	a[pos] = 'a';
	out[pos] = id;
	++pos;
	int count{1};
	while(pos < n)
	{
		if(a[pos] != 'a')
		{
			if(a[pos] == cur)
			{
				if((count&1) || id == 1)process(pos);
				else
				{
					--id;
					return;
				}
			}
			else
			{
				if(cur == '1') cur = '0';
				else cur = '1';
				out[pos] = id;
				a[pos] = 'a';
				++count;
			}
		}
		++pos;
	}
	--id;
}

int main()
{
    int t;
    scanf("%i", &t);
    while(t--)
    {
		scanf("%i", &n);

		a.resize(n);
		out.resize(n);
		id = 0;
		max = 0;

		scanf("%s", &a[0]);

		process(0);
		printf("%i\n", max);
		for(int i{}; i < n; ++i)
		{
			printf("%i ", out[i]);
		}
		putchar('\n');
	}
}


#include <bits/stdc++.h>

std::vector<char> a;
std::vector<int> out;

int id;
int n;
int max;

void process(int pos)
{
	++id;
	if(id > max) max = id;
	char cur = a[pos];
	a[pos] = 'a';
	out[pos] = id;
	++pos;
	int count{1};
	while(pos < n)
	{
		if(a[pos] != 'a')
		{
			if(a[pos] == cur)
			{
				if(count&1 || id == 1)process(pos);
				else
				{
					--id;
					return;
				}
			}
			else
			{
				if(cur == '1') cur = '0';
				else cur = '1';
				out[pos] = id;
				a[pos] = 'a';
				++count;
			}
		}
		++pos;
	}
	--id;
}

int main()
{
    int t;
    scanf("%i", &t);
    while(t--)
    {
		scanf("%i", &n);

		a.resize(n);
		out.resize(n);
		id = 0;
		max = 0;

		scanf("%s", &a[0]);

		process(0);
		printf("%i\n", max);
		for(int i{}; i < n; ++i)
		{
			printf("%i ", out[i]);
		}
		putchar('\n');
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    std::cin >> t;
    while(t--)
    {
        int n;
        std::cin >> n;
        int count = n;
        int layer = 0;
        std::string a(' ', n);
        std::vector<int> out(n);
        std::cin >> a;
        char last{0};
        while(count > 0)
        {
            last = 0;
            ++layer;
            for(int i{}; i < n; ++i)
            {
                if (a[i] != 0)
                    if (last != 0)
                    {
                        if(a[i] != last)
                        {
                            --count;
                            last = a[i];
                            a[i] = 0;
                            out[i] = layer;
                        }
                    }
                    else
                    {
                        last = a[i];
                        a[i] = 0;
                        out[i] = layer;
                        --count;
                    }

            }
        }
        std::cout << layer << '\n';
        for(int i{}; i<n; ++i) std::cout << out[i] << ' ';
        std::cout << '\n';
    }
    return 0;
}


#include<bits/stdc++.h>

#define PRIME 1000000007
#define REDUCE_IO_TIME ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int, int>
#define I first
#define II second
#define INPUT_AR(ar, n) for(int i=0; i<n; i++) cin >> ar[i];

#define MAX 200005

using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i;
    set<int> zeros, ones;
    for(i=0; i<n; i++){
        if(s[i] == '0'){
            zeros.insert(i);
        }
        else{
            ones.insert(i);
        }
    }
    zeros.insert(INT_MAX);
    ones.insert(INT_MAX);

    int ans[n] = {}, mx = 0, sum=0;
    while(zeros.size() > 1 || ones.size() > 1){
        mx++;
        i = min((*zeros.begin()), *ones.begin());
        if(i == INT_MAX){
            break;
        }
        while(i != INT_MAX){
            ans[i] = mx;
            ones.erase(i);
            zeros.erase(i);

            if(s[i] == '0'){
                i = *upper_bound(ones.begin(), ones.end(), i);
            }
            else{
                i = *upper_bound(zeros.begin(), zeros.end(), i);
            }
        }

    }

    cout << mx << '\n';
    for(i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << '\n';
}

int main(){
    REDUCE_IO_TIME
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>

#define PRIME 1000000007
#define REDUCE_IO_TIME ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int, int>
#define I first
#define II second
#define INPUT_AR(ar, n) for(int i=0; i<n; i++) cin >> ar[i];

#define MAX 200005

using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i;
    set<int> zeros, ones;
    for(i=0; i<n; i++){
        if(s[i] == '0'){
            zeros.insert(i);
        }
        else{
            ones.insert(i);
        }
    }
    zeros.insert(INT_MAX);
    ones.insert(INT_MAX);

    int ans[n] = {}, mx = 0, sum=0;
    while(zeros.size() > 1 || ones.size() > 1){
        mx++;
        i = min((*zeros.begin()), *ones.begin());
        if(i == INT_MAX){
            break;
        }
        while(i != INT_MAX){
            ans[i] = mx;
            ones.erase(i);
            zeros.erase(i);

            if(s[i] == '0'){
                i = *upper_bound(ones.begin(), ones.end(), i);
            }
            else{
                i = *upper_bound(zeros.begin(), zeros.end(), i);
            }
        }

    }

    cout << mx << endl;
    for(i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}

int main(){
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>

#define PRIME 1000000007
#define REDUCE_IO_TIME ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int, int>
#define I first
#define II second
#define INPUT_AR(ar, n) for(int i=0; i<n; i++) cin >> ar[i];

#define MAX 200005

using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i;
    int ans[n] = {}, mx = 1;
    ans[0] = 1;
    for(i=1; i<n; i++){
        if(s[i] != s[i-1]){
            ans[i] = 1;
        }
        else{
            ans[i] = ans[i-1] + 1;
        }
        mx = max(mx, ans[i]);
    }
    cout << mx << endl;
    for(i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}

int main(){
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>

#define PRIME 1000000007
#define REDUCE_IO_TIME ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int, int>
#define I first
#define II second
#define INPUT_AR(ar, n) for(int i=0; i<n; i++) cin >> ar[i];

#define MAX 200005

using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i;
    set<int> zeros, ones;
    for(i=0; i<n; i++){
        if(s[i] == '0'){
            zeros.insert(i);
        }
        else{
            ones.insert(i);
        }
    }
    zeros.insert(n);
    ones.insert(n);

    int ans[n] = {}, mx = 0, sum=0;
    while(1){
        mx++;
        // if(mx >= n+2){
        //     throw "NEVERMIND";
        //     return;
        // }

        i = min(*zeros.begin(), *ones.begin());
        if(i == n){
            mx--;
            break;
        }
        while(i != n){
            ans[i] = mx;
            if(s[i] == '0'){
                zeros.erase(i);
                // i = *upper_bound(ones.begin(), ones.end(), i);
                i = *ones.upper_bound(i);
            }
            else{
                ones.erase(i);
                // i = *upper_bound(zeros.begin(), zeros.end(), i);
                i = *zeros.upper_bound(i);
            }
        }
    }

    cout << mx << '\n';
    for(i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << '\n';
}

int main(){
    REDUCE_IO_TIME
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>

#define PRIME 1000000007
#define REDUCE_IO_TIME ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int, int>
#define I first
#define II second
#define INPUT_AR(ar, n) for(int i=0; i<n; i++) cin >> ar[i];

#define MAX 200005

using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i;
    set<int> zeros, ones;
    for(i=0; i<n; i++){
        if(s[i] == '0'){
            zeros.insert(i);
        }
        else{
            ones.insert(i);
        }
    }
    zeros.insert(INT_MAX);
    ones.insert(INT_MAX);

    int ans[n] = {}, mx = 0, sum=0;
    while(1){
        mx++;
        i = min((*zeros.begin()), *ones.begin());
        if(i == INT_MAX){
            mx--;
            break;
        }
        while(i != INT_MAX){
            ans[i] = mx;

            if(s[i] == '0'){
                zeros.erase(i);
                i = *upper_bound(ones.begin(), ones.end(), i);
            }
            else{
                ones.erase(i);
                i = *upper_bound(zeros.begin(), zeros.end(), i);
            }
        }

    }

    cout << mx << '\n';
    for(i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << '\n';
}

int main(){
    REDUCE_IO_TIME
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>

#define PRIME 1000000007
#define REDUCE_IO_TIME ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int, int>
#define I first
#define II second
#define INPUT_AR(ar, n) for(int i=0; i<n; i++) cin >> ar[i];

#define MAX 200005

using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i;
    set<int> zeros, ones;
    for(i=0; i<n; i++){
        if(s[i] == '0'){
            zeros.insert(i);
        }
        else{
            ones.insert(i);
        }
    zeros.insert(INT_MAX);
    ones.insert(INT_MAX);
    }

    int ans[n] = {}, mx = 0, sum=0;
    while(1){
        mx++;
        if(mx >= n+2){
            throw "NEVERMIND";
            return;
        }

        i = min((*zeros.begin()), *ones.begin());
        if(i == INT_MAX){
            mx--;
            break;
        }
        while(i != INT_MAX){
            ans[i] = mx;
            if(s[i] == '0'){
                zeros.erase(i);
                i = *upper_bound(ones.begin(), ones.end(), i);
            }
            else{
                ones.erase(i);
                i = *upper_bound(zeros.begin(), zeros.end(), i);
            }
        }

    }

    cout << mx << '\n';
    for(i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << '\n';
}

int main(){
    REDUCE_IO_TIME
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>

#define PRIME 1000000007
#define REDUCE_IO_TIME ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int, int>
#define I first
#define II second
#define INPUT_AR(ar, n) for(int i=0; i<n; i++) cin >> ar[i];

#define MAX 200005

using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i;
    set<int> zeros, ones;
    for(i=0; i<n; i++){
        if(s[i] == '0'){
            zeros.insert(i);
        }
        else{
            ones.insert(i);
        }
    }
    zeros.insert(n);
    ones.insert(n);

    int ans[n] = {}, mx = 0, sum=0;
    while(1){
        mx++;
        // if(mx >= n+2){
        //     throw "NEVERMIND";
        //     return;
        // }

        i = min((*zeros.begin()), *ones.begin());
        if(i == n){
            mx--;
            break;
        }
        while(i != n){
            ans[i] = mx;
            if(s[i] == '0'){
                zeros.erase(i);
                i = *upper_bound(ones.begin(), ones.end(), i);
            }
            else{
                ones.erase(i);
                i = *upper_bound(zeros.begin(), zeros.end(), i);
            }
        }

    }

    cout << mx << '\n';
    for(i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << '\n';
}

int main(){
    REDUCE_IO_TIME
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>

#define PRIME 1000000007
#define REDUCE_IO_TIME ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int, int>
#define I first
#define II second
#define INPUT_AR(ar, n) for(int i=0; i<n; i++) cin >> ar[i];

#define MAX 200005

using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i;
    set<int> zeros, ones;
    for(i=0; i<n; i++){
        if(s[i] == '0'){
            zeros.insert(i);
        }
        else{
            ones.insert(i);
        }
    }
    zeros.insert(INT_MAX);
    ones.insert(INT_MAX);

    int ans[n] = {}, mx = 0, sum=0;
    while(1){
        mx++;
        if(mx >= n+2){
            throw "NEVERMIND";
        }

        i = min((*zeros.begin()), *ones.begin());
        if(i == INT_MAX){
            mx--;
            break;
        }
        while(i != INT_MAX){
            ans[i] = mx;
            if(s[i] == '0'){
                zeros.erase(i);
                i = *upper_bound(ones.begin(), ones.end(), i);
            }
            else{
                ones.erase(i);
                i = *upper_bound(zeros.begin(), zeros.end(), i);
            }
        }

    }

    cout << mx << '\n';
    for(i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << '\n';
}

int main(){
    REDUCE_IO_TIME
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}