#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    set<int> ones;
    set<int> zeros;
    for (int i = 0 ; i < n ; i++) {
      if (s[i] == '1') ones.insert(i);
      else zeros.insert(i);
    }

    int group = 1;
    vector<int> ans (n);
    char last_c = (s[0] == '1') ? '0' : '1';
    int last_pos = -1;
    while (ones.size()>0 || zeros.size()>0) {
      // cout << last_c << " " << last_pos << endl;
      if (last_c == '0') {
        auto next = ones.upper_bound(last_pos);
        if (next == ones.end()) {
          // reset
          group ++;
          if (ones.size() == 0) {last_c = '1'; last_pos = *zeros.begin()-1;}
          else if (zeros.size() == 0) { last_c = '0'; last_pos = *ones.begin()-1;}
          else {
            last_c = (*zeros.begin() < *ones.begin()) ? '1' : '0';
            last_pos = ((*zeros.begin() < *ones.begin()) ? *zeros.begin() : *ones.begin()) - 1;
          }
        } else {
          ans[*next] = group;
          last_c = '1';
          last_pos = *next;
          ones.erase(next);
        }
      } else {
        auto next = zeros.upper_bound(last_pos);
        if (next == zeros.end()) {
          // reset
          group ++;
          if (ones.size() == 0) {last_c = '1'; last_pos = *zeros.begin()-1;}
          else if (zeros.size() == 0) { last_c = '0'; last_pos = *ones.begin()-1;}
          else {
            last_c = (*zeros.begin() < *ones.begin()) ? '1' : '0';
            last_pos = ((*zeros.begin() < *ones.begin()) ? *zeros.begin() : *ones.begin()) - 1;
          }
        } else {
          ans[*next] = group;
          last_c = '0';
          last_pos = *next;
          zeros.erase(next);
        }
      }
    }
    cout << group << endl;
    for (auto & i : ans) cout << i << " ";
    cout << endl;

  }

}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    if (n == 1) {
      cout << 1 << endl << 1 << endl;
      continue;
    }
    vector<int> alternate(2*n,-1);
    int fill_pos = 0;
    char next_char = s[0];
    for (int i = 0 ; i < n ; i++)
    {
      if (s[i] == next_char) {
        alternate[fill_pos] = i;
        fill_pos += 2;
      }
    }
    next_char = (next_char == '1') ? '0' : '1';
    fill_pos = 1;
    for (int i = 0 ; i < n ; i++)
    {
      if (s[i] == next_char) {
        alternate[fill_pos] = i;
        fill_pos += 2;
      }
    }
    alternate.erase(find_if(alternate.rbegin(),alternate.rend(),[](int i) { return i != -1 ;}).base(),alternate.end());
    // for (auto & i : alternate) cout << i << ' ';
    // cout << endl;

    vector<int> ans(n);
    int group = 1;
    for (int i = 0 ; i < (int)alternate.size()-1 ; i++)
    {
      if (alternate[i] != -1) ans[alternate[i]] = group;
      if (alternate[i+1] < alternate[i] ) {
        group ++;
      }
    }

    if (alternate[alternate.size()-1] < alternate[alternate.size()-2]) group++;
    ans[n-1] = group;
    cout << group << endl;
    for (auto & i : ans) cout << i << " ";
    cout<< endl;
  }

}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 1;
		int pre = 1, cur = 1;
		int ppre = 1;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) {
				a[i] = 1;
				ppre = pre;
				pre = cur;
				cur = 1;
			}
			else {
				a[i] = a[i - 1] + 1;
				cur ++;
				if(a[i - 1] == pre) a[i] = max(ppre, pre) + 1;
			}
			mx = max(mx, a[i]);
		}
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		int cnt = 0;
		cin >> n;
		string s;
		cin >> s;
		VI seq[2];
		int ans[n];
		_rep(i, 0, n){
			int x = s[i] - '0';
			if(seq[!x].empty()){
				seq[x].pb(++cnt);
				ans[i] = cnt;
			}
			else{
				seq[x].pb(seq[!x].back());
				seq[!x].pop_back();
				ans[i] = seq[x].back();
			}
		}
		cout  << cnt << endl;
		_rep(i, 0, n) cout << ans[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 1;
		int pre = -1, cur = 1;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) {
				a[i] = 1;
				pre = cur;
				cur = 1;
			}
			else {
				a[i] = a[i - 1] + 1;
				if(a[i - 1] == pre) {
					if (i - pre - pre >= 1)
						a[i] = a[i - pre - pre - 1] + 1;
					else a[i] = 2;
				}
				cur = a[i];
			}
			mx = max(mx, a[i]);
		}
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 1;
		int pre = -1, cur = 1;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) {
				a[i] = 1;
				pre = cur;
				cur = 1;
			}
			else {
				a[i] = a[i - 1] + 1;
				if(a[i - 1] == pre)
					a[i] = a[i - pre - pre - 1] + 1;

				cur = a[i];
			}
			mx = max(mx, a[i]);
		}
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 1;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) a[i] = 1;
			else a[i] = a[i - 1] + 1;
			mx = max(mx, a[i]);
		}
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/problemset/problem/1399/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef vector<int> VI;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		VI stk[2];
		int id = 0;
		VI ans;
		_rep(i, 0, 2) stk[i].clear();
		for(char& c : s){
			int x = c - '0';
			if(stk[!x].empty())
				stk[x].eb(++ id);
			else{
				stk[x].eb(stk[!x].back());
				stk[!x].pop_back();
			}
			ans.eb(stk[x].back());
		}
		cout << id << endl;
		_rep(i, 0, n) cout << ans[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 1;
		//int cur = 1;
		int len[2];
		len[0] = len[1] = -1;
		len[s[0] - '0'] = 1;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) {
				a[i] = 1;
				len[s[i - 1] - '0'] = max(a[i - 1], len[s[i - 1] - '0']);
			}
			else {
				a[i] = a[i - 1] + 1;
				int x = s[i] - '0';
				if(a[i] > len[!x] && len[!x] != -1){
					//cout << i << endl;
					a[i] = max(len[!x], len[x]) + 1;
					len[x] = max(len[x],a[i]);
				}
				//len[x] = max(len[x], a[i]);
			}
			mx = max(mx, a[i]);
		}
		//cout << len[0] << " " << len[1] << endl;
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		int cnt = 0;
		cin >> n;
		string s;
		cin >> s;
		VI seq[2];
		int ans[n];
		_rep(i, 0, n){
			int x = s[i] - '0';
			if(seq[!x].empty()){
				seq[x].pb(++cnt);
				ans[i] = cnt;
			}
			else{
				seq[x].pb(seq[!x].back());
				seq[!x].pop_back();
				ans.pb(seq[x].back());
			}
		}
		cout  << cnt << endl;
		_rep(i, 0, n) cout << ans[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 1;
		int pre = -1, cur = 1;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) {
				a[i] = 1;
				pre = cur;
				cur = 1;
			}
			else {
				a[i] = a[i - 1] + 1;
				if(a[i - 1] == pre) {
					if (i - pre - pre >= 1)
						a[i] = max(a[i - pre - pre - 1], pre) + 1;
					else a[i] = pre + 1;
				}
				cur = a[i];
			}
			mx = max(mx, a[i]);
		}
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 1;
		int pre = 1, cur = 1;
		int ppre = 1;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) {
				a[i] = 1;
				ppre = pre;
				pre = cur;
				cur = 1;
			}
			else {
				a[i] = a[i - 1] + 1;
				if(a[i - 1] == pre) a[i] = max(ppre, pre) + 1;
				cur = a[i];
			}
			mx = max(mx, a[i]);
		}
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 0;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) a[i] = 1;
			else a[i] = a[i - 1] + 1;
			mx = max(mx, a[i]);
		}
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		int cnt = 0;
		cin >> n;
		string s;
		cin >> s;
		VI seq[2];
		int ans[n];
		_rep(i, 0, n){
			int x = s[i] - '0';
			if(seq[!x].empty()){
				seq[x].pb(++cnt);
				ans[i] = cnt;
			}
			else{
				seq.pb(seq[!x].back());
				seq[!x].pop_back();
				ans.pb(seq[x].back());
			}
		}
		cout  << cnt << endl;
		_rep(i, 0, n) cout << ans[i] << " \n"[i == n - 1];
	}
	return 0;
}


// Problem : D. Binary String To Subsequences
// Contest : Codeforces - Codeforces Round #661 (Div. 3)
// URL : https://codeforces.com/contest/1399/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PDD pair<db,db>
#define eb emplace_back
#define pb push_back
#define sf scanf
#define pf printf
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int a[n];
		memset(a, 0, sizeof a);
		a[0] = 1;
		int mx = 1;
		int pre = 1, cur = 1;
		int t = 1;
		_rep(i, 1, n){
			if(s[i] != s[i - 1]) {
				a[i] = 1;
				t = pre;
				pre = cur;
				cur = 1;
			}
			else {
				a[i] = a[i - 1] + 1;
				cur ++;
				if(a[i - 1] == pre) a[i] = t + 1;
			}
			mx = max(mx, a[i]);
		}
		cout << mx << endl;
		_rep(i, 0, n) cout << a[i] << " \n"[i == n - 1];
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define sci(a) scanf("%d",&a)

char str[100009];
int ans[100009];
int zro[100009];
int one[100009];

int main()
{
   // freopen("input.txt","r",stdin);
    int t;sci(t);
    while(t--){
        int n;sci(n);

        scanf("%s",str);
        int Sz1=0,Sz0=0;

        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(Sz0>0){
                    int x=zro[Sz0];Sz0--;
                    Sz1++;
                    one[Sz1]=x;
                    ans[i]=x;
                }
                else{
                    cnt++;
                    Sz1++;
                    one[Sz1]=cnt;
                    ans[i]=cnt;
                }
            }
            else{
                if(Sz1>0){
                    int y=one[Sz1];Sz1--;
                    Sz0++;
                    zro[Sz0]=y;
                    ans[i]=y;
                }
                else{
                    cnt++;
                    Sz0++;
                    zro[Sz0]=cnt;
                    ans[i]=cnt;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}
char str[100009];
int ans[100009];
int zro[100009];
int one[100009];

int main()
{
    //freopen("input.txt","r",stdin);
    int t;sci(t);
    while(t--){
        int n;sci(n);

        scanf("%s",str);
        int Sz1=0,Sz0=0;

        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(Sz0>0){
                    int x=zro[Sz0];Sz0--;
                    Sz1++;
                    one[Sz1]=x;
                    ans[i]=x;
                }
                else{
                    cnt++;
                    Sz1++;
                    one[Sz1]=cnt;
                    ans[i]=cnt;
                }
            }
            else{
                if(Sz1>0){
                    int y=one[Sz1];Sz1--;
                    Sz0++;
                    zro[Sz0]=y;
                    ans[i]=y;
                }
                else{
                    cnt++;
                    Sz0++;
                    zro[Sz0]=cnt;
                    ans[i]=cnt;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}
char str[100009];
int ans[100009];

int main()
{
    //freopen("input.txt","r",stdin);
    Case{
        int n;sci(n);

        scanf("%s",str);
        stack<int>zro;
        stack<int>one;

        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(!zro.empty()){
                    int x=zro.top();zro.pop();
                    one.push(x);
                    ans[i]=x;
                }
                else{
                    cnt++;
                    one.push(cnt);
                    ans[i]=cnt;
                }
            }
            else{
                if(!one.empty()){
                    int y=one.top();one.pop();
                    zro.push(y);
                    ans[i]=y;
                }
                else{
                    cnt++;
                    zro.push(cnt);
                    ans[i]=cnt;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}

int main()
{
    freopen("input.txt","r",stdin);
    Case{
        int n;sci(n);
        char str[100009];
        scanf("%s",str);
        stack<int>zro;
        stack<int>one;
        int ans[n+1];
        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(!zro.empty()){
                    int x=zro.top();zro.pop();
                    one.push(x);
                    ans[i]=x;
                }
                else{
                    cnt++;
                    one.push(cnt);
                    ans[i]=cnt;
                }
            }
            else{
                if(!one.empty()){
                    int y=one.top();one.pop();
                    zro.push(y);
                    ans[i]=y;
                }
                else{
                    cnt++;
                    zro.push(cnt);
                    ans[i]=cnt;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}

char str[100009];

int main()
{
    //freopen("input.txt","r",stdin);
    Case{
        int n;sci(n);
        scanf("%s",str);
        stack<int>zro;
        stack<int>one;
        int ans[n+1];
        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(!zro.empty()){
                    int x=zro.top();zro.pop();
                    one.push(x);
                    ans[i]=x;
                }
                else{
                    cnt++;
                    one.push(cnt);
                    ans[i]=cnt;
                }
            }
            else{
                if(!one.empty()){
                    int y=one.top();one.pop();
                    zro.push(y);
                    ans[i]=y;
                }
                else{
                    cnt++;
                    zro.push(cnt);
                    ans[i]=cnt;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}

int main()
{
    freopen("input.txt","r",stdin);
    Case{
        int n;sci(n);
        char str[100009];
        scanf("%s",str);
        stack<int>zro;
        stack<int>one;
        int ans[n+1];
        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(!zro.empty()){
                    int x=zro.top();zro.pop();
                    one.push(x);
                    ans[i]=x;
                }
                else{
                    cnt++;
                    one.push(cnt);
                    ans[i]=cnt;
                }
            }
            else{
                if(!one.empty()){
                    int y=one.top();one.pop();
                    zro.push(y);
                    ans[i]=y;
                }
                else{
                    cnt++;
                    zro.push(cnt);
                    ans[i]=cnt;
                }
            }
        }
        cout<<cnt<<endl;
        for(int i=0;i<n;i++)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}

int main()
{
    //freopen("input.txt","r",stdin);
    Case{
        int n;sci(n);
        char str[100009];
        scanf("%s",str);
        stack<int>zro;
        stack<int>one;
        int ans[n+1];
        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(!zro.empty()){
                    int x=zro.top();zro.pop();
                    one.push(x);
                    ans[i]=x;
                }
                else{
                    cnt++;
                    one.push(cnt);
                    ans[i]=cnt;
                }
            }
            else{
                if(!one.empty()){
                    int y=one.top();one.pop();
                    zro.push(y);
                    ans[i]=y;
                }
                else{
                    cnt++;
                    zro.push(cnt);
                    ans[i]=cnt;
                }
            }
        }
        cout<<cnt<<endl;
        for(int i=0;i<n;i++)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}
char str[100009];
int ans[100009];

int main()
{
    //freopen("input.txt","r",stdin);
    int t;sci(t);
    while(t--){
        int n;sci(n);

        scanf("%s",str);
        stack<int>zro;
        stack<int>one;

        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(!zro.empty()){
                    int x=zro.top();zro.pop();
                    one.push(x);
                    ans[i]=x;
                }
                else{
                    cnt++;
                    one.push(cnt);
                    ans[i]=cnt;
                }
            }
            else{
                if(!one.empty()){
                    int y=one.top();one.pop();
                    zro.push(y);
                    ans[i]=y;
                }
                else{
                    cnt++;
                    zro.push(cnt);
                    ans[i]=cnt;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}
char str[200009];
int ans[200009];

int main()
{
    //freopen("input.txt","r",stdin);
    int t;sci(t);
    while(t--){
        int n;sci(n);

        scanf("%s",str);
        stack<int>zro;
        stack<int>one;

        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(!zro.empty()){
                    int x=zro.top();zro.pop();
                    one.push(x);
                    ans[i]=x;
                }
                else{
                    cnt++;
                    one.push(cnt);
                    ans[i]=cnt;
                }
            }
            else{
                if(!one.empty()){
                    int y=one.top();one.pop();
                    zro.push(y);
                    ans[i]=y;
                }
                else{
                    cnt++;
                    zro.push(cnt);
                    ans[i]=cnt;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define visited 1
#define pi acos(-1)
#define pbk push_back
#define inf 1<<30
#define lli long long int
#define sci(a) scanf("%d",&a)
#define sci2(a,b) sci(a);sci(b)
#define scli(a) scanf("%lld",&a)
#define scli2(a,b) scli(a);scli(b)
#define Case int t,cs=0;scanf("%d",&t);while(++cs<=t)
void sciar(int a[],int n){for(int i=0;i<n;i++)scanf("%d",&a[i]);}

int main()
{
    //freopen("input.txt","r",stdin);
    Case{
        int n;sci(n);
        char str[100009];
        scanf("%s",str);
        stack<int>zro;
        stack<int>one;
        int ans[n+1];
        int cnt=0;
        for(int i=0;i<n;i++){
            if(str[i]=='1'){
                if(!zro.empty()){
                    int x=zro.top();zro.pop();
                    one.push(x);
                    ans[i]=x;
                }
                else{
                    cnt++;
                    one.push(cnt);
                    ans[i]=cnt;
                }
            }
            else{
                if(!one.empty()){
                    int y=one.top();one.pop();
                    zro.push(y);
                    ans[i]=y;
                }
                else{
                    cnt++;
                    zro.push(cnt);
                    ans[i]=cnt;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n;
		cin >> n;
		string s;
		cin >> s;
		int vis[n] = {0}, count = 1, r = 1;
		bool flag = s[0] - '0';
		vector<int> ans(n);
		vector<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.pb(i);
			else zero.pb(i);
		}
		int idx = 1;
		while (1)
		{
			bool chance;
			auto ito = one.begin();
			auto itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					if (!vis[i])
					{
						vis[i] = 1;
						ans[i] = r;
						r++;
					}
				}
				break;
			}
			while (itz != zero.end() || ito != one.end())
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						vis[*ito] = 1;
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						vis[*itz] = 1;
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		cout << r-1<< endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n,r=1,idx=0;
		string s;
		cin >> n >> s;
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		while (!one.empty()&&!zero.empty())
		{
			bool chance;
			auto ito = one.begin(),itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else break;
			while (1)
			{
				if (chance)
				{
					chance = 0;
					ito = one.lower_bound(idx);
					if (ito == one.end())
						break;
					else
					{
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(*ito);
					}
				}
				else
				{
					chance = 1;
					itz = zero.lower_bound(idx);
					if (itz == zero.end())
						break;
					else
					{
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(*itz);
					}
				}
			}
			r++;
		}
		for(auto ind:one)
		{
		    ans[ind]=r;
		    r++;
		}
		for(auto ind:zero)
		{
		    ans[ind]=r;
		    r++;
		}
		cout << r-1<< endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n;
		cin >> n;
		string s;
		cin >> s;
		int vis[n] = {0}, count = 1, r = 1;
		bool flag = s[0] - '0';
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		int idx = 1;
		while (1)
		{
			bool chance;
			auto ito = one.begin();
			auto itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					if (!vis[i])
					{
						vis[i] = 1;
						ans[i] = r;
						r++;
					}
				}
				break;
			}
			while (itz != zero.end() || ito != one.end())
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						vis[*ito] = 1;
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						vis[*itz] = 1;
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		cout << r << endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n,r=1,idx=0;
		string s;
		cin >> n >> s;
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		while (!one.empty()&&!zero.empty())
		{
			bool chance;
			auto ito = one.begin(),itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else break;
			while (1)
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(*ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(*itz);
					}
				}
			}
			r++;
		}
		for(auto ind:one)
		{
		    ans[ind]=r;
		    r++;
		}
		for(auto ind:zero)
		{
		    ans[ind]=r;
		    r++;
		}
		cout << r-1<< endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n,r=1,idx=0;
		string s;
		cin >> n >> s;
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		while (!one.empty()&&!zero.empty())
		{
			bool chance;
			auto ito = one.begin(),itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else break;
			while (1)
			{
				if (chance)
				{
					chance = 0;
					ito = one.lower_bound(idx);
					if (ito == one.end())
						break;
					else
					{
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = zero.lower_bound(idx);
					if (itz == zero.end())
						break;
					else
					{
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		for(auto ind:one)
		{
		    ans[ind]=r;
		    r++;
		}
		for(auto ind:zero)
		{
		    ans[ind]=r;
		    r++;
		}
		cout << r-1<< endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n,r=1,idx=1;
		string s;
		cin >> n >> s;
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		while (1)
		{
			bool chance;
			auto ito = one.begin(),itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else
			{
				for (int i = 0; i < n; i++)
			    {
					ans[i] = r;
					r++;
				}
				break;
			}
			while (1)
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		cout << r-1<< endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n;
		cin >> n;
		string s;
		cin >> s;
		int vis[n] = {0}, count = 1, r = 1;
		bool flag = s[0] - '0';
		vector<int> ans(n);
		vector<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.pb(i);
			else zero.pb(i);
		}
		int idx = 1;
		while (1)
		{
			bool chance;
			auto ito = one.begin();
			auto itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					if (!vis[i])
					{
						vis[i] = 1;
						ans[i] = r;
						r++;
					}
				}
				break;
			}
			while (itz != zero.end() || ito != one.end())
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						vis[*ito] = 1;
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						vis[*itz] = 1;
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		cout << r << endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n,r=1,idx=0;
		string s;
		cin >> n >> s;
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		while (!one.empty()&&!zero.empty())
		{
			bool chance;
			auto ito = one.begin(),itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else break;
			while (1)
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		for(auto ind:one)
		{
		    ans[ind]=r;
		    r++;
		}
		for(auto ind:zero)
		{
		    ans[ind]=r;
		    r++;
		}
		cout << r-1<< endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n;
		cin >> n;
		string s;
		cin >> s;
		int vis[n] = {0}, count = 1, r = 1;
		bool flag = s[0] - '0';
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		int idx = 1;
		while (1)
		{
			bool chance;
			auto ito = one.begin();
			auto itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					if (!vis[i])
					{
						vis[i] = 1;
						ans[i] = r;
						r++;
					}
				}
				break;
			}
			while (itz != zero.end() || ito != one.end())
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						vis[*ito] = 1;
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						vis[*itz] = 1;
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		cout << r-1 << endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n;
		cin >> n;
		string s;
		cin >> s;
		int vis[n] = {0}, count = 1, r = 1;
		bool flag = s[0] - '0';
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		int idx = 1;
		while (1)
		{
			bool chance;
			auto ito = one.begin();
			auto itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					if (!vis[i])
					{
						vis[i] = 1;
						ans[i] = r;
						r++;
					}
				}
				break;
			}
			while (itz != zero.end() || ito != one.end())
			{
				if (chance)
				{
					chance = 0;
					ito = one.lower_bound(idx);
					if (ito == one.end())
						break;
					else
					{
						vis[*ito] = 1;
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = zero.lower_bound(idx);
					if (itz == zero.end())
						break;
					else
					{
						vis[*itz] = 1;
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		cout << r-1 << endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n,r=1,idx=1;
		string s;
		cin >> n >> s;
		vector<int> ans(n);
		set<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.insert(i);
			else zero.insert(i);
		}
		while (1)
		{
			bool chance;
			auto ito = one.begin(),itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else
			{
				for (int i = 0; i < n; i++)
			    {
					ans[i] = r;
					r++;
				}
				break;
			}
			while (itz != zero.end() && ito != one.end())
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		cout << r-1<< endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define endl 			"\n"
#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 pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int n;
		cin >> n;
		string s;
		cin >> s;
		int vis[n] = {0}, count = 1, r = 1;
		bool flag = s[0] - '0';
		vector<int> ans(n);
		vector<int> one, zero;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0')
				one.pb(i);
			else zero.pb(i);
		}
		int idx = 1;
		while (1)
		{
			bool chance;
			auto ito = one.begin();
			auto itz = zero.begin();
			if (itz != zero.end() && ito != one.end())
			{
				chance = (*ito) < (*itz);
				idx = min(*ito, *itz);
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					if (!vis[i])
					{
						vis[i] = 1;
						ans[i] = r;
						r++;
					}
				}
				break;
			}
			while (itz != zero.end() && ito != one.end())
			{
				if (chance)
				{
					chance = 0;
					ito = lower_bound(one.begin(), one.end(), idx);
					if (ito == one.end())
						break;
					else
					{
						vis[*ito] = 1;
						ans[*ito] = r;
						idx = (*ito + 1);
						one.erase(ito);
					}
				}
				else
				{
					chance = 1;
					itz = lower_bound(zero.begin(), zero.end(), idx);
					if (itz == zero.end())
						break;
					else
					{
						vis[*itz] = 1;
						ans[*itz] = r;
						idx = (*itz + 1);
						zero.erase(itz);
					}
				}
			}
			r++;
		}
		cout << r-1<< endl;
		for (int i = 0; i < n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;
}


#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;
                }
                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;
                    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>

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';
            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());

        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>

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
            {
                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>

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;
            }
        }

        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;
}

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';
            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());

        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()
{

    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>

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 (true || validatee(i, sol))
        {
            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-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 (true || validatee(i, sol))
        {
            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>

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;

        bool first = false;

        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
            {
                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';