#include <bits/stdc++.h>
using namespace std;
set<int> s[2];
int m[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string str;
    cin >> str;
    s[0].clear();
    s[1].clear();
    for (int i = 0; i < n; i++) s[str[i] - '0'].insert(i);
    int sz = 1, f, idx = -1;
    while ((!s[0].empty()) && (!s[1].empty())) {
      if ((*s[0].begin()) > (*s[1].begin()))
        f = 1;
      else
        f = 0;
      while (1) {
        auto pos = s[f].lower_bound(idx);
        if (pos == s[f].end()) {
          idx = -1;
          break;
        } else {
          idx = (*pos);
          s[f].erase(idx);
          m[idx] = sz;
          f = 1 - f;
        }
      }
      sz++;
    }
    for (auto it : s[0]) m[it] = sz++;
    for (auto it : s[1]) m[it] = sz++;
    cout << sz - 1 << '\n';
    for (int i = 0; i < n; i++) cout << m[i] << " ";
    cout << '\n';
  }
  return 0;
}
