#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   long long powMod(long long x, long long y) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % ((long long)1e9 + 7);       }       y /= 2;       x = (x * x) % ((long long)1e9 + 7);     }     return p;   }   long long CpowMod(long long x, long long y, long long w) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % w;       }       y /= 2;       x = (x * x) % w;     }     return p;   }   long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }   long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   void solve() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n, 0);       string s;       cin >> s;       map<long long, set<long long> > m;       map<long long, vector<long long> > v;       long long num = 1;       for (int i = 0; i <= n - 1; i++) {         long long x = s[i] -  0 ;         long long y = 1 - x;         if ((long long)m[y].size()) {           long long in = *m[y].rbegin();           m[y].erase(in);           m[x].insert(in);           v[in].push_back(i);         } else {           m[x].insert(num);           v[num].push_back(i);           num++;         }       }       for (auto &it : v) {         for (auto &is : it.second) {           a[is] = it.first;         }       }       cout << num - 1 <<   n ;       for (auto &it : a) {         cout << it <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     solve();     return 0;   }   