#include <bits/stdc++.h>
using namespace std;
long long t, n, len0 = 0, len1 = 0, len = 0, maxv = 0;
long long a[200005], ans[200005], x[200005], y[200005];
signed main() {
  cin >> t;
  while (t--) {
    cin >> n;
    len = 0, len0 = 0, len1 = 0, maxv = 0;
    for (long long i = 1; i <= n; i++) {
      char x;
      cin >> x;
      a[i] = x - '0';
    }
    for (long long i = 1; i <= n; i++) {
      long long now = a[i] ^ 1;
      if (now == 0) {
        if (len0 >= 1) {
          ans[i] = x[len0];
          len1++;
          y[len1] = x[len0];
          len0--;
        } else {
          len++, len1++;
          y[len1] = len;
          ans[i] = len;
        }
      } else {
        if (len1 >= 1) {
          ans[i] = y[len1];
          len0++;
          x[len0] = y[len1];
          len1--;
        } else {
          len++, len0++;
          x[len0] = len;
          ans[i] = len;
        }
      }
      maxv = max(maxv, ans[i]);
    }
    cout << maxv << endl;
    for (long long i = 1; i <= n; i++) cout << ans[i] << ' ';
    cout << endl;
  }
  return 0;
}
