#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   int t,n;
   string s;
   //cin>>t;
   scanf("%d",&t);
   while(t--)
   {
      vector<ll> v;
      priority_queue<ll> pq;
      //cin>>n;
      scanf("%d",&n);
      cin>>s;
      int one=0,zero=0;
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         {
            zero=0;
            one++;
            pq.push(one);
            v.push_back(one);
         }
         else
         {
            one=0;
            zero++;
            pq.push(zero);
            v.push_back(zero);
         }
      }
      cout<<pq.top()<<endl;
      for(ll i=0;i<n;i++)
         cout<<v[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   int t,n;
   string s;
   scanf("%d",&t);
   while(t--)
   {
      vector<ll> v;
      priority_queue<ll> pq0,pq1;
      cin>>n;
      cin>>s;
      ll one=0,zero=0,str1=0,str0=0;
      pq0.push(0);
      pq1.push(0);
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         {
            zero=0;
            if(str0!=0)
            {
               one++;
               str1++;
               str0--;
            }
            else
            {
               one=pq1.top();
               one++;
               str1++;
            }
            pq1.push(one);
            v.push_back(one);
         }
         else
         {
            one=0;
            if(str1!=0)
            {
               zero++;
               str0++;
               str1--;
            }
            else
            {
               zero=pq0.top();
               zero++;
               str0++;
            }
            pq0.push(zero);
            v.push_back(zero);
         }
      }
      cout<<max(pq0.top(),pq1.top())<<endl;
      for(ll i=0;i<n;i++)
         cout<<v[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define       MX                 200005
int seq[MX];
set<int> st1,st0;
set<int>::iterator it0,it1;
int main(void)
{
   int t,n;
   string s;
   cin>>t;
   while(t--)
   {
      cin>>n;
      cin>>s;
      for(int i=0;i<n;i++)
      {
         if(s[i]=='1')
            st1.insert(i);
         else
            st0.insert(i);
      }
      int cnt=1;
      while(1)
      {
         if(st0.size()==0)
         {
            while(st1.size()!=0)
            {
               it1=st1.begin();
               seq[*it1]=cnt;
               cnt++;
               st1.erase(it1);
            }
            break;
         }
         if(st1.size()==0)
         {
            while(st0.size()!=0)
            {
               it0=st0.begin();
               seq[*it0]=cnt;
               cnt++;
               st0.erase(it0);
            }
            break;
         }
         int x=*st0.begin();
         int y=*st1.begin();
         int c,p;
         if(x<y)
         {
            st0.erase(st0.begin());
            c=0;
            p=x;
         }
         else
         {
            st1.erase(st1.begin());
            c=1;
            p=y;
         }
         seq[p]=cnt;
         while(1)
         {
               if(c==0)
               {
                     it1=st1.upper_bound(p);
                     if(it1==st1.end())
                        break;
                     p=*it1;
                     seq[*it1]=cnt;
                     st1.erase(it1);
                     c=1;
               }
               else
               {
                     it0=st0.upper_bound(p);
                     if(it0==st0.end())
                        break;
                     p=*it0;
                     seq[*it0]=cnt;
                     st0.erase(it0);
                     c=0;
               }
         }
         cnt++;
      }
      cout<<cnt-1<<endl;
      for(int i=0;i<n;i++)
         cout<<seq[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define       MX                 200005
int seq[MX];
set<int> st1,st0;
set<int>::iterator it0,it1;
int main(void)
{
   int t,n;
   string s;
   cin>>t;
   while(t--)
   {
      cin>>n;
      cin>>s;
      for(int i=0;i<n;i++)
      {
         if(s[i]=='1')
            st1.insert(i);
         else
            st0.insert(i);
      }
      int cnt=1;
      while(1)
      {
         if(st0.size()==0)
         {
            while(st1.size()!=0)
            {
               it1=st1.begin();
               seq[*it1]=cnt;
               cnt++;
               st1.erase(it1);
            }
            break;
         }
         if(st1.size()==0)
         {
            while(st0.size()!=0)
            {
               it0=st0.begin();
               seq[*it0]=cnt;
               cnt++;
               st0.erase(it0);
            }
            break;
         }
         int x=*st0.begin();
         int y=*st1.begin();
         int c,p;
         if(x<y)
         {
            seq[x]=cnt;
            st0.erase(st0.begin());
            c=0;
            p=x;
         }
         else
         {
            seq[y]=cnt;
            st1.erase(st1.begin());
            c=1;
            p=y;
         }
         while(1)
         {
               if(c==0)
               {
                     it1=st1.upper_bound(p);
                     if(it1==st1.end())
                        break;
                     p=*it1;
                     seq[*it1]=cnt;
                     st1.erase(it1);
                     c=1;
               }
               else
               {
                     it0=st0.upper_bound(*it1);
                     if(it0==st0.end())
                        break;
                     p=*it0;
                     seq[*it0]=cnt;
                     st0.erase(it0);
                     c=0;
               }
         }
         cnt++;
      }
      cout<<cnt-1<<endl;
      for(int i=0;i<n;i++)
         cout<<seq[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   ll t,n;
   string s;
   cin>>t;
   while(t--)
   {
      vector<ll> v;
      cin>>n;
      cin>>s;
      ll one=0,zero=0,str1=0,str0=0,mx0=0,mx1=0;
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         {
            zero=0;
            if(str0!=0)
               str0--;
            else
               one=mx1;
            one++;
            str1++;
            mx1=max(mx1,one);
            v.push_back(one);
         }
         else
         {
            one=0;
            if(str1!=0)
               str1--;
            else
               zero=mx0;
            zero++;
            str0++;
            mx0=max(mx0,zero);
            v.push_back(zero);
         }
      }
      cout<<max(mx0,mx1)<<endl;
      for(ll i=0;i<n;i++)
         cout<<v[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
ll seq[200005];
int main(void)
{
   ll t,n;
   string s;
   cin>>t;
   while(t--)
   {
      set<ll> st1,st0;
      set<ll>::iterator it0,it1;
      cin>>n;
      cin>>s;
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
            st1.insert(i);
         else
            st0.insert(i);
      }
      ll cnt=1;
      while(st1.size()!=0 || st0.size()!=0)
      {
         if(st0.size()==0)
         {
            while(st1.size()!=0)
            {
               it1=st1.begin();
               seq[*it1]=cnt;
               cnt++;
               st1.erase(it1);
            }
         }
         else if(st1.size()==0)
         {
            while(st0.size()!=0)
            {
               it0=st0.begin();
               seq[*it0]=cnt;
               cnt++;
               st0.erase(it0);
            }
         }
         else
         {
            it0=st0.begin();
            it1=st1.begin();
            if(*it0<*it1)
            {
               //it0=st0.begin();
               seq[*it0]=cnt;
               st0.erase(it0);
               ll c=0;
               while(1)
               {
                  if(c%2!=0)
                  {
                     it0=st0.upper_bound(*it1);
                     if(it0==st0.end())
                     break;
                     seq[*it0]=cnt;
                     st0.erase(it0);
                  }
                  else
                  {
                     it1=st1.upper_bound(*it0);
                     if(it1==st1.end())
                     break;
                     seq[*it1]=cnt;
                     st1.erase(it1);
                  }
                  c++;
               }
            }
            else
            {
               seq[*it1]=cnt;
               st1.erase(it1);
               ll c=0;
               while(1)
               {
                  if(c%2!=0)
                  {
                     it1=st1.upper_bound(*it0);
                     if(it1==st1.end())
                     break;
                     seq[*it1]=cnt;
                     st1.erase(it1);
                  }
                  else
                  {
                     it0=st0.upper_bound(*it1);
                     if(it0==st0.end())
                     break;
                     seq[*it0]=cnt;
                     st0.erase(it0);
                  }
                  c++;
               }
            }
            cnt++;
         }
      }
      cout<<cnt-1<<endl;
      for(ll i=0;i<n;i++)
         cout<<seq[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   ll t,n;
   string s;
   cin>>t;
   while(t--)
   {
      vector<ll> v;
      cin>>n;
      cin>>s;
      ll one=0,zero=0,str1=0,str0=0,mx0=0,mx1=0;
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         {
            zero=0;
            if(str0!=0)
               str0--;
            else
               one=mx1;
            one++;
            //str1++;
            str1=one;
            mx1=max(mx1,one);
            v.push_back(one);
         }
         else
         {
            one=0;
            if(str1!=0)
               str1--;
            else
               zero=mx0;
            zero++;
            str0=zero;
            mx0=max(mx0,zero);
            v.push_back(zero);
            //if(s[i+1]=='1')
               //str1=0;
         }
      }
      cout<<max(mx0,mx1)<<endl;
      for(ll i=0;i<n;i++)
         cout<<v[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   int t,n;
   string s;
   //cin>>t;
   scanf("%d",&t);
   while(t--)
   {
      vector<ll> v;
      priority_queue<ll> pq,pq0,pq1;
      //cin>>n;
      scanf("%d",&n);
      cin>>s;
      int one=0,zero=0,str1=0,str0=0;
      pq0.push(0);
      pq1.push(0);
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         {
            pq0.push(str0);
            zero=0;
            if(str0!=0)
            {
               one++;
               str1=str1+1;
               pq.push(one);
               pq1.push(one);
               v.push_back(one);
               str0--;
               continue;
            }
            else
            {
               one=pq1.top();
               one++;
               str1=str1+1;
               pq1.push(one);
               pq.push(one);
               v.push_back(one);
            }
            //one++;
            //str1=str1+1;
            /*if(zero!=0)
               zero--;*/
            //pq.push(one);
            //v.push_back(one);
         }
         else
         {
            pq1.push(str1);
            one=0;
            if(str1!=0)
            {
               zero++;
               str0=str0+1;
               pq.push(zero);
               pq0.push(zero);
               v.push_back(zero);
               str1--;
               continue;
            }
            else
            {
               zero=pq0.top();
               zero++;
               str0=str0+1;
               pq0.push(zero);
               pq.push(zero);
               v.push_back(zero);
            }
            //zero++;
            //str0=str0+1;
            /*if(one!=0)
               one--;*/
            //pq.push(zero);
            //v.push_back(zero);
         }
      }
      cout<<pq.top()<<endl;
      for(ll i=0;i<n;i++)
         cout<<v[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   int t,n;
   string s;
   scanf("%d",&t);
   while(t--)
   {
      vector<ll> v;
      priority_queue<ll> pq,pq0,pq1;
      cin>>n;
      cin>>s;
      int one=0,zero=0,str1=0,str0=0;
      pq0.push(0);
      pq1.push(0);
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         {
            pq0.push(str0);
            zero=0;
            if(str0!=0)
            {
               one++;
               str1=str1+1;
               pq.push(one);
               pq1.push(one);
               v.push_back(one);
               str0--;
            }
            else
            {
               one=pq1.top();
               one++;
               str1=str1+1;
               pq1.push(one);
               pq.push(one);
               v.push_back(one);
            }
         }
         else
         {
            pq1.push(str1);
            one=0;
            if(str1!=0)
            {
               zero++;
               str0=str0+1;
               pq.push(zero);
               pq0.push(zero);
               v.push_back(zero);
               str1--;
            }
            else
            {
               zero=pq0.top();
               zero++;
               str0=str0+1;
               pq0.push(zero);
               pq.push(zero);
               v.push_back(zero);
            }
         }
      }
      cout<<pq.top()<<endl;
      for(ll i=0;i<n;i++)
         cout<<v[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   int t,n;
   string s;
   scanf("%d",&t);
   while(t--)
   {
      vector<ll> v;
      priority_queue<ll> pq,pq0,pq1;
      cin>>n;
      cin>>s;
      ll one=0,zero=0,str1=0,str0=0;
      pq0.push(0);
      pq1.push(0);
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         {
            zero=0;
            if(str0!=0)
            {
               one++;
               str1=str1+1;
               pq.push(one);
               pq1.push(one);
               v.push_back(one);
               str0--;
            }
            else
            {
               one=pq1.top();
               one++;
               str1=str1+1;
               pq1.push(one);
               pq.push(one);
               v.push_back(one);
            }
         }
         else
         {
            one=0;
            if(str1!=0)
            {
               zero++;
               str0=str0+1;
               pq.push(zero);
               pq0.push(zero);
               v.push_back(zero);
               str1--;
            }
            else
            {
               zero=pq0.top();
               zero++;
               str0=str0+1;
               pq0.push(zero);
               pq.push(zero);
               v.push_back(zero);
            }
         }
      }
      cout<<pq.top()<<endl;
      for(ll i=0;i<n;i++)
         cout<<v[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int seq[200001];
set<int> st1,st0;
set<int>::iterator it0,it1;
int main(void)
{
   int t,n;
   string s;
   cin>>t;
   while(t--)
   {
      cin>>n;
      cin>>s;
      for(int i=0;i<n;i++)
      {
         if(s[i]=='1')
            st1.insert(i);
         else
            st0.insert(i);
      }
      int cnt=1;
      while(st1.size()!=0 || st0.size()!=0)
      {
         if(st0.size()==0)
         {
            while(st1.size()!=0)
            {
               it1=st1.begin();
               seq[*it1]=cnt;
               cnt++;
               st1.erase(it1);
            }
            break;
         }
         if(st1.size()==0)
         {
            while(st0.size()!=0)
            {
               it0=st0.begin();
               seq[*it0]=cnt;
               cnt++;
               st0.erase(it0);
            }
            break;
         }
         //else
         {
            it0=st0.begin();
            it1=st1.begin();
            if(*it0<*it1)
            {
               seq[*it0]=cnt;
               st0.erase(it0);
               int c=0;
               while(1)
               {
                  if(c%2!=0)
                  {
                     it0=st0.lower_bound(*it1);
                     if(it0==st0.end())
                        break;
                     seq[*it0]=cnt;
                     st0.erase(it0);
                  }
                  else
                  {
                     it1=st1.lower_bound(*it0);
                     if(it1==st1.end())
                        break;
                     seq[*it1]=cnt;
                     st1.erase(it1);
                  }
                  c++;
               }
            }
            else
            {
               seq[*it1]=cnt;
               st1.erase(it1);
               int c=0;
               while(1)
               {
                  if(c%2!=0)
                  {
                     it1=st1.upper_bound(*it0);
                     if(it1==st1.end())
                        break;
                     seq[*it1]=cnt;
                     st1.erase(it1);
                  }
                  else
                  {
                     it0=st0.upper_bound(*it1);
                     if(it0==st0.end())
                        break;
                     seq[*it0]=cnt;
                     st0.erase(it0);
                  }
                  c++;
               }
            }
            cnt++;
         }
      }
      cout<<cnt-1<<endl;
      for(int i=0;i<n;i++)
         cout<<seq[i]<<" ";
      cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   ll t,n,a[200001];
   string s;
   cin>>t;
   while(t--)
   {
      vector< pair <ll,ll> >p1,p2;
      vector< pair <char,ll> >sp;
      vector< pair <char,ll> >::iterator it;
      priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair <ll,ll> > > plpq;
      cin>>n;
      cin>>s;
      ll one=0,zero=0,flag,cnt1=1,cnt2=1;
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         one++;
         else
         zero++;
         sp.push_back(make_pair(s[i],i));
      }
      //flag=0;
      while(sp.size()!=0)
      {
         if(sp[0].first=='1')
         flag=1;
         else
         flag=0;
         if((flag==0 && zero==0)||(flag==1 && one==0))
            break;
         for(ll i=0;i<sp.size();i++)
         {
            if(flag==0 && zero==0)
               break;
            if(flag==1 && one==0)
               break;
            if(flag==0 && sp[i].first=='0')
            {
               flag=1;
               zero--;
               p1.push_back(make_pair(sp[i].second,cnt1));
               it=sp.begin()+i;
               sp.erase(it);
               i--;
            }
            else if(flag==1 && sp[i].first=='1')
            {
               flag=0;
               one--;
               p1.push_back(make_pair(sp[i].second,cnt1));
               it=sp.begin()+i;
               sp.erase(it);
               i--;
            }
         }
         //cout<<sp<<endl;
         cnt1++;
      }
      if(sp.size()==0)
         plpq.push(make_pair(cnt1-1,1));
      //cout<<cnt1-1<<endl;
      /*sp.clear();
      one=0,zero=0;
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         one++;
         else
         zero++;
         sp.push_back(make_pair(s[i],i));
      }
      flag=1;
      while(sp.size()!=0)
      {
         //flag=1;
         if((flag==0 && zero==0)||(flag==1 && one==0))
            break;
         for(ll i=0;i<sp.size();i++)
         {
            if(flag==0 && zero==0)
               break;
            if(flag==1 && one==0)
               break;
            if(flag==0 && sp[i].first=='0')
            {
               flag=1;
               zero--;
               p2.push_back(make_pair(sp[i].second,cnt2));
               it=sp.begin()+i;
               sp.erase(it);
               i--;
            }
            else if(flag==1 && sp[i].first=='1')
            {
               flag=0;
               one--;
               p2.push_back(make_pair(sp[i].second,cnt2));
               it=sp.begin()+i;
               sp.erase(it);
               i--;
            }
         }
         //cout<<sp<<endl;
         cnt2++;
      }
      if(sp.size()==0)
         plpq.push(make_pair(cnt2-1,2));
      //cout<<cnt2-1<<endl;*/
      cout<<plpq.top().first<<endl;
      //if(plpq.top().second==1)
      //{
         sort(p1.begin(),p1.end());
         for(ll i=0;i<p1.size();i++)
            cout<<p1[i].second<<" ";
         cout<<endl;
      //}
      //else
      //{

         //sort(p2.begin(),p2.end());
         //for(ll i=0;i<p2.size();i++)
            //cout<<p2[i].second<<" ";
         //cout<<endl;
      //}
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
int main(void)
{
   int t,n;
   string s;
   //cin>>t;
   scanf("%d",&t);
   while(t--)
   {
      vector< pair <int,int> >p1;
      vector< pair <char,int> >sp;
      vector< pair <char,int> >::iterator it;
      //cin>>n;
      scanf("%d",&n);
      cin>>s;
      int one=0,zero=0,flag,cnt1=1;
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
         one++;
         else
         zero++;
         sp.push_back(make_pair(s[i],i));
      }
      while(sp.size()!=0)
      {
         if(sp[0].first=='1')
         flag=1;
         else
         flag=0;
         if((zero==0 && one!=0)||(zero!=0 && one==0))
         {
            for(ll i=0;i<sp.size();i++)
            {
               p1.push_back(make_pair(sp[i].second,cnt1));
               cnt1++;
            }
            break;
         }
         if((flag==0 && zero==0)||(flag==1 && one==0))
            break;
         for(ll i=0;i<sp.size();i++)
         {
            if(flag==0 && zero==0)
               break;
            if(flag==1 && one==0)
               break;
            if(flag==0 && sp[i].first=='0')
            {
               flag=1;
               zero--;
               p1.push_back(make_pair(sp[i].second,cnt1));
               it=sp.begin()+i;
               sp.erase(it);
               i--;
            }
            else if(flag==1 && sp[i].first=='1')
            {
               flag=0;
               one--;
               p1.push_back(make_pair(sp[i].second,cnt1));
               it=sp.begin()+i;
               sp.erase(it);
               i--;
            }
         }
         cnt1++;
      }
      //cout<<cnt1-1<<endl;
      printf("%d\n",cnt1-1);
      sort(p1.begin(),p1.end());
      for(ll i=0;i<p1.size();i++)
         printf("%d ",p1[i].second);
         //cout<<p1[i].second<<" ";
      printf("\n");
      //cout<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
ll seq[200005];
set<ll> st1,st0;
set<ll>::iterator it0,it1;
int main(void)
{
   ll t,n;
   string s;
   cin>>t;
   while(t--)
   {
      cin>>n;
      cin>>s;
      for(ll i=0;i<n;i++)
      {
         if(s[i]=='1')
            st1.insert(i);
         else
            st0.insert(i);
      }
      ll cnt=1;
      while(st1.size()!=0 && st0.size()!=0)
      {
            it0=st0.begin();
            it1=st1.begin();
            if(*it0<*it1)
            {
               seq[*it0]=cnt;
               st0.erase(it0);
               ll c=0;
               while(1)
               {
                  if(c%2!=0)
                  {
                     it0=st0.upper_bound(*it1);
                     if(it0==st0.end())
                     break;
                     seq[*it0]=cnt;
                     st0.erase(it0);
                  }
                  else
                  {
                     it1=st1.upper_bound(*it0);
                     if(it1==st1.end())
                     break;
                     seq[*it1]=cnt;
                     st1.erase(it1);
                  }
                  c++;
               }
            }
            else
            {
               seq[*it1]=cnt;
               st1.erase(it1);
               ll c=0;
               while(1)
               {
                  if(c%2!=0)
                  {
                     it1=st1.upper_bound(*it0);
                     if(it1==st1.end())
                     break;
                     seq[*it1]=cnt;
                     st1.erase(it1);
                  }
                  else
                  {
                     it0=st0.upper_bound(*it1);
                     if(it0==st0.end())
                     break;
                     seq[*it0]=cnt;
                     st0.erase(it0);
                  }
                  c++;
               }
            }
            cnt++;
      }
      if(st0.size()==0)
      {
         while(st1.size()!=0)
         {
               it1=st1.begin();
               seq[*it1]=cnt;
               cnt++;
               st1.erase(it1);
         }
      }
      else if(st1.size()==0)
      {
         while(st0.size()!=0)
         {
               it0=st0.begin();
               seq[*it0]=cnt;
               cnt++;
               st0.erase(it0);
         }
      }
      cout<<cnt-1<<endl;
      for(ll i=0;i<n;i++)
         cout<<seq[i]<<" ";
      cout<<endl;
      st1.clear();
      st0.clear();
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis;
int grp = 1;
vi ans;
void dfs(int pos, seti &pos0, seti &pos1, string s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	//cout<<pos<<" ";
	if(s[pos] == '0')
	{
		//auto it = lb(all(pos1), pos);
		auto it = pos1.lb(pos);
		if(it != pos1.end())
		{

			int next = *it;
			pos1.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		//auto it = lb(all(pos0), pos);
		auto it = pos0.lb(pos);
		if(it != pos0.end())
		{
			int next = *it;
			pos0.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		seti pos0, pos1;
		ans.assign(n, 0);
		vis.assign(n,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.insert(i);
			else
				pos1.insert(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				//cout<<"\n";
				++grp;
			}
		}
		cout<<grp - 1<<"\n";
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis;
int grp = 1;
vi ans;
void dfs(int pos, seti &pos0, seti &pos1, string &s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	//cout<<pos<<" ";
	if(s[pos] == '0')
	{
		if(!pos1.size())
			return ;
		auto it = pos1.lb(pos);
		if(it != pos1.end())
		{

			int next = *it;
			pos1.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		if(!pos0.size())
			return ;
		auto it = pos0.lb(pos);
		if(it != pos0.end())
		{
			int next = *it;
			pos0.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		seti pos0, pos1;
		ans.assign(200001, 0);
		vis.assign(200001,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.insert(i);
			else
				pos1.insert(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				//cout<<"\n";
				++grp;
			}
		}
		cout<<grp - 1<<"\n";
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis(200001,0);
vi adj[200001];

int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vi vec(n);
		string s;
		cin>>s;
		vi vec0, vec1, ans(n);

		for(int i=0; i<n; ++i)
		{
			int newpos = SZ(vec0) + SZ(vec1);
			if(s[i] == '0')
			{
				if(!SZ(vec1))
				{
					vec0.pb(i);
				}
				else
				{
					newpos = vec1.back();
					vec1.pop_back();
					vec0.pb(newpos);
				}
			}
			else
			{
				if(!SZ(vec0))
				{
					vec1.pb(i);
				}
				else
				{
					newpos = vec0.back();
					vec0.pop_back();
					vec1.pb(newpos);
				}
			}
			ans[i] = newpos;
		}
		for(auto x : ans)
			cout<<x + 1<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis;
int grp = 1;
vi ans;
void dfs(int pos, seti &pos0, seti &pos1, string s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	//cout<<pos<<" ";
	if(s[pos] == '0')
	{
		if(!pos0.size())
			return ;
		auto it = pos1.lb(pos);
		if(it != pos1.end())
		{

			int next = *it;
			pos1.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		if(!pos0.size())
			return ;
		auto it = pos0.lb(pos);
		if(it != pos0.end())
		{
			int next = *it;
			pos0.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		seti pos0, pos1;
		ans.assign(n, 0);
		vis.assign(n,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.insert(i);
			else
				pos1.insert(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				++grp;
			}
		}
		cout<<grp - 1<<"\n";
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis(200001,0);
vi adj[200001];

int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vi vec(n);
		string s;
		cin>>s;
		vi vec0, vec1, ans(n);

		for(int i=0; i<n; ++i)
		{
			int newpos = SZ(vec0) + SZ(vec1);
			if(s[i] == '0')
			{
				if(!SZ(vec1))
				{
					vec0.pb(i);
				}
				else
				{
					newpos = vec1.back();
					vec1.pop_back();
					vec0.pb(newpos);
				}
			}
			else
			{
				if(!SZ(vec0))
				{
					vec1.pb(i);
				}
				else
				{
					newpos = vec0.back();
					vec0.pop_back();
					vec1.pb(newpos);
				}
			}
			ans[i] = newpos;
		}
		for(auto x : ans)
			cout<<x + 1<<" ";
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis(200001,0);
vi adj[200001];

int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vi vec(n);
		string s;
		cin>>s;
		vi vec0, vec1, ans(n);
		for(int i=0; i<n; ++i)
		{
			int newpos = SZ(vec0) + SZ(vec1);
			if(s[i] == '0')
			{
				if(!SZ(vec1))
				{
					vec0.pb(i);
				}
				else
				{
					newpos = vec1.back();
					vec1.pop_back();
					vec0.pb(newpos);
				}
			}
			else
			{
				if(!SZ(vec0))
				{
					vec1.pb(i);
				}
				else
				{
					newpos = vec0.back();
					vec0.pop_back();
					vec1.pb(newpos);
				}
			}
			ans[i] = newpos;
		}
		cout<<vec0.size() + vec1.size()<<"\n";
		for(auto x : ans)
			cout<<x + 1<<" ";
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis(200001,0);

int grp = 1;
vi ans;
void dfs(int pos, seti &pos0, seti &pos1, string s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	//cout<<pos<<" ";
	if(s[pos] == '0')
	{
		//auto it = lb(all(pos1), pos);
		auto it = pos1.lb(pos);
		if(it != pos1.end())
		{

			int next = *it;
			pos1.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		//auto it = lb(all(pos0), pos);
		auto it = pos0.lb(pos);
		if(it != pos0.end())
		{
			int next = *it;
			pos0.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		seti pos0, pos1;
		ans.assign(n, 0);
		vis.assign(200001,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.insert(i);
			else
				pos1.insert(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				//cout<<"\n";
				++grp;
			}
		}
		cout<<grp - 1<<"\n";
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis(200001,0);
vi adj[200001];

int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vi vec(n);
		string s;
		cin>>s;
		vi vec0, vec1, ans(n);
		for(int i=0; i<n; ++i)
		{
			int newpos = SZ(vec0) + SZ(vec1);
			if(s[i] == '0')
			{
				if(!SZ(vec1))
				{
					vec0.pb(newpos);
				}
				else
				{
					newpos = vec1.back();
					vec1.pop_back();
					vec0.pb(newpos);
				}
			}
			else
			{
				if(!SZ(vec0))
				{
					vec1.pb(newpos);
				}
				else
				{
					newpos = vec0.back();
					vec0.pop_back();
					vec1.pb(newpos);
				}
			}
			ans[i] = newpos;
		}
		cout<<vec0.size() + vec1.size()<<"\n";
		for(auto x : ans)
			cout<<x + 1<<" ";
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis(200001,0);

int grp = 1;
vi ans;

void dfs(int pos, vi &pos0, vi &pos1, string s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	if(s[pos] == '0')
	{
		auto it = lb(all(pos1), pos);
		if(it != pos1.end())
		{
			int next = *(lb(all(pos1), pos));
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		auto it = lb(all(pos0), pos);
		if(it != pos0.end())
		{
			int next = *(lb(all(pos0), pos));
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		vi pos0, pos1;
		ans.assign(n, 0);
		vis.assign(200001,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.pb(i);
			else
				pos1.pb(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				++grp;
			}
		}
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis;
int grp = 1;
vi ans;
void dfs(int pos, seti &pos0, seti &pos1, string s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	//cout<<pos<<" ";
	if(s[pos] == '0')
	{
		if(!pos1.size())
			return ;
		auto it = pos1.lb(pos);
		if(it != pos1.end())
		{

			int next = *it;
			pos1.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		if(!pos0.size())
			return ;
		auto it = pos0.lb(pos);
		if(it != pos0.end())
		{
			int next = *it;
			pos0.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		seti pos0, pos1;
		ans.assign(n, 0);
		vis.assign(n,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.insert(i);
			else
				pos1.insert(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				//cout<<"\n";
				++grp;
			}
		}
		cout<<grp - 1<<"\n";
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis;
int grp = 1;
vi ans;
void dfs(int pos, seti &pos0, seti &pos1, string &s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	//cout<<pos<<" ";
	if(s[pos] == '0')
	{
		if(!pos1.size())
			return ;
		auto it = pos1.lb(pos);
		if(it != pos1.end())
		{

			int next = *it;
			pos1.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		if(!pos0.size())
			return ;
		auto it = pos0.lb(pos);
		if(it != pos0.end())
		{
			int next = *it;
			pos0.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		seti pos0, pos1;
		ans.assign(n, 0);
		vis.assign(n,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.insert(i);
			else
				pos1.insert(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				//cout<<"\n";
				++grp;
			}
		}
		cout<<grp-1<<"\n";
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis;
int grp = 1;
vi ans;
void dfs(int pos, seti &pos0, seti &pos1, string &s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	//cout<<pos<<" ";
	if(s[pos] == '0')
	{
		if(!pos1.size())
			return ;
		auto it = pos1.lb(pos);
		if(it != pos1.end())
		{

			int next = *it;
			pos1.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		if(!pos0.size())
			return ;
		auto it = pos0.lb(pos);
		if(it != pos0.end())
		{
			int next = *it;
			pos0.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		seti pos0, pos1;
		ans.assign(n, 0);
		vis.assign(200001,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.insert(i);
			else
				pos1.insert(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				//cout<<"\n";
				++grp;
			}
		}
		cout<<grp - 1<<"\n";
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>  // For Ordered Set
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define SZ(x) ((int)(x).size())
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound // returns iterator to either the searched elements index or smallest number higher than searched's index (Keep 2 cases in mind) 1. ptr.end() 2. when ptr points to the searched element
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
/*
READ THIS
1. Always use find function for maps.
2. Try not to use floats and doubles and use long double if necessary.
3. double arguments can seriously slow down some programs.. TC
4. auto does not work in bitsets, use normal for loop
*/

ll modulo_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int palindromecheck(string s){int n = s.size();for(int i=0; i<n/2; ++i){if(s[i]!=s[n-i-1]){return 0;}}return 1;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}

vi vis;
int grp = 1;
vi ans;
void dfs(int pos, seti &pos0, seti &pos1, string &s)
{
	vis[pos] = 1;
	ans[pos] = grp;
	//cout<<pos<<" ";
	if(s[pos] == '0')
	{
		if(!pos1.size())
			return ;
		auto it = pos1.lb(pos);
		if(it != pos1.end())
		{

			int next = *it;
			pos1.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		else
			return ;
	}
	else
	{
		if(!pos0.size())
			return ;
		auto it = pos0.lb(pos);
		if(it != pos0.end())
		{
			int next = *it;
			pos0.erase(it);
			//cout<<s[pos]<<" "<<pos<<" "<<next<<"\n";
			dfs(next, pos0, pos1, s);
		}
		return ;
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		seti pos0, pos1;
		ans.assign(n, 0);
		vis.assign(n,0);
		grp = 1;
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == '0')
				pos0.insert(i);
			else
				pos1.insert(i);
		}

		for(int i=0; i<n; ++i)
		{
			if(!vis[i])
			{
				dfs(i, pos0, pos1, s);
				//cout<<"\n";
				++grp;
			}
		}
		cout<<grp - 1<<"\n";
		for(auto x : ans)
		{
			cout<<x<<" ";
		}
		cout<<"\n";
	}
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		vector<set<int> > ind(2);
		for(int i=0;i<n;i++){
			ind[(s[i]=='1')].insert(i);
		}
		// for(int i=0;i<2;i++){
		// 	for(auto x:ind[i])
		// 		cout<<x<<" ";
		// 	cout<<endl;
		// }
		int mark[n]={0};
		int k=1;
		while(!ind[0].empty() && !ind[1].empty()){
			int i=min(*ind[0].begin(),*ind[1].begin());
			int flag= (s[i]!='1');
			ind[1-flag].erase(i);
			mark[i]=k;
			auto x=ind[flag].lower_bound(i);
			while(x!=ind[flag].end()){
				mark[*x]=k;
				ind[flag].erase(x);
				flag=1-flag;
				x=ind[flag].lower_bound(*x);
			}
			k++;
		}
		while(!ind[0].empty()){
			mark[*ind[0].begin()]=k;
			ind[0].erase(ind[0].begin());
			k++;
		}
		while(!ind[1].empty()){
			mark[*ind[1].begin()]=k;
			ind[1].erase(ind[1].begin());
			k++;
		}
		cout<<k-1<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

	return 0;

}


//#include<bits/stdc++.h>
//#include <time.h>
#include<set>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int k=1;
		vector<set<int> > pos(2);
		int mark[n]={0};
		for(int i=0;i<n;i++){
			int flag=s[i]=='1';
				if(pos[1-flag].empty()){
					mark[i]=k;
					pos[flag].insert(k);
					k++;
				}
				else{
					mark[i]=*pos[1-flag].begin();
					pos[flag].insert(*pos[1-flag].begin());
					pos[1-flag].erase(pos[1-flag].begin());
				}
		}
		cout<<k-1<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

	return 0;

}


//#include<bits/stdc++.h>
//#include <time.h>
#include<set>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		vector<set<int> > ind(2);
		for(int i=0;i<n;i++){
			ind[(s[i]=='1')].insert(i);
		}
		// for(int i=0;i<2;i++){
		// 	for(auto x:ind[i])
		// 		cout<<x<<" ";
		// 	cout<<endl;
		// }
		int mark[n]={0};
		int k=1;
		while(!ind[0].empty() && !ind[1].empty()){
			int i=min(*ind[0].begin(),*ind[1].begin());
			int flag= (s[i]!='1');
			ind[1-flag].erase(i);
			mark[i]=k;
			auto x=ind[flag].lower_bound(i);
			while(x!=ind[flag].end()){
				mark[*x]=k;
				ind[flag].erase(x);
				flag=1-flag;
				x=ind[flag].lower_bound(*x);
			}
			k++;
		}
		while(!ind[0].empty()){
			mark[*ind[0].begin()]=k;
			ind[0].erase(ind[0].begin());
			k++;
		}
		while(!ind[1].empty()){
			mark[*ind[1].begin()]=k;
			ind[1].erase(ind[1].begin());
			k++;
		}
		cout<<k-1<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

	return 0;

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		vector<set<int> > ind(2);
		for(int i=0;i<n;i++){
			ind[(s[i]=='1')].insert(i);
		}
		// for(int i=0;i<2;i++){
		// 	for(auto x:ind[i])
		// 		cout<<x<<" ";
		// 	cout<<endl;
		// }
		int mark[n]={0};
		int k=1;
		while(!ind[0].empty() && !ind[1].empty()){
			int i=min(*ind[0].begin(),*ind[1].begin());
			int flag= (s[i]!='1');
			ind[1-flag].erase(i);
			mark[i]=k;
			auto x=ind[flag].lower_bound(i);
			while(x!=ind[flag].end()){
				mark[*x]=k;
				ind[flag].erase(x);
				flag=1-flag;
				x=ind[flag].lower_bound(*x);
			}
			k++;
		}
		for(auto x: ind[0]){
			mark[x]=k;
			k++;
		}
		for(auto x: ind[1]){
			mark[x]=k;
			k++;
		}
		cout<<k-1<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

	return 0;

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int mark[n]={0};
		int k=1;
		int flag= (s[0]=='1');
		mark[0]=k;
		int ans=1;
		int i=1;
		while(i<n){
			while(i<n && s[i]== ('0'+ flag)){
				k++;
				mark[i]=k;
				i++;
			}
			flag=1-flag;
			ans=max(ans,k);
			k=0;
		}
		cout<<ans<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int mark[n]={0};
		int k=1;
		int flag= s[0]=='1';
		mark[0]=k;
		int ans=0;
		int i=1;
		while(i<n){
			while(i<n && s[i]== ('0' +flag)){
				k++;
				mark[i]=k;
				i++;
			}
			flag=1-flag;
			ans=max(ans,k);
			k=0;
		}
		cout<<ans<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		vector<set<int> > ind(2);
		for(int i=0;i<n;i++){
			ind[(s[i]=='1')].insert(i);
		}
		// for(int i=0;i<2;i++){
		// 	for(auto x:ind[i])
		// 		cout<<x<<" ";
		// 	cout<<endl;
		// }
		int mark[n]={0};
		int k=1;
		while(!ind[0].empty() && !ind[1].empty()){
			int i=min(*ind[0].begin(),*ind[1].begin());
			int flag= (s[i]=='1');
			ind[flag].erase(i);
			mark[i]=k;
			auto x=ind[1-flag].lower_bound(i);
			//cout<<i<<" "<<flag<<" "<<*x<<endl;
			while(x!=ind[1-flag].end()){
				mark[*x]=k;
				ind[1-flag].erase(x);
				flag=1-flag;
				x=ind[1-flag].lower_bound(*x);
			}
			k++;
		}
		for(auto x: ind[0]){
			mark[x]=k;
			k++;
		}
		for(auto x: ind[1]){
			mark[x]=k;
			k++;
		}
		cout<<k-1<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

	return 0;

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		vector<set<int> > ind(2);
		for(int i=0;i<n;i++){
			ind[(s[i]=='1')].insert(i);
		}
		// for(int i=0;i<2;i++){
		// 	for(auto x:ind[i])
		// 		cout<<x<<" ";
		// 	cout<<endl;
		// }
		int mark[n]={0};
		int k=1;
		while(!ind[0].empty() && !ind[1].empty()){
			int i=min(*ind[0].begin(),*ind[1].begin());
			int flag= s[i]=='1';
			ind[flag].erase(i);
			mark[i]=k;
			auto x=ind[1-flag].lower_bound(i);
			//cout<<i<<" "<<flag<<" "<<*x<<endl;
			while(x!=ind[1-flag].end()){
				mark[*x]=k;
				ind[1-flag].erase(x);
				flag=1-flag;
				x=ind[1-flag].lower_bound(*x);
			}
			k++;
		}
		for(auto x: ind[0]){
			mark[x]=k;
			k++;
		}
		for(auto x: ind[1]){
			mark[x]=k;
			k++;
		}
		cout<<k-1<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 50001

#define ll long long int
vector<int> adjl[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int mark[n]={0};
		int k=1;
		int flag= (s[0]=='1');
		mark[0]=k;
		int ans=1;
		int i=1;
		int lk=-1;
		int llk=-1;
		while(i<n){
			while(i<n && s[i]== ('0'+ flag)){
				k++;
				if(lk!=-1 &&llk!=-1 && lk<llk && k==lk+1){
					k=llk+1;
				}
				mark[i]=k;
				i++;
			}
			flag=1-flag;
			ans=max(ans,k);
			llk=lk;
			lk=k;
			k=0;
		}
		cout<<ans<<endl;
		for(auto x: mark)
			cout<<x<<" ";
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      string s;
      cin>>s;
      vector<int>ans(n,0);
      int mx=1;
      int cnt0=0,cnt1=0;
      int i=0;
      while(i<n)
      {
          int cnt0=1;
          int cnt1=1;
          if(s[i]=='0'){
          while(s[i]=='0'&&i<n)
          {
              ans[i]=cnt0;
              cnt0++;
              i++;
          }
          }
          else
          {
             while(s[i]=='1'&&i<n)
          {
              ans[i]=cnt1;
              cnt1++;
              i++;
          }
          }
      }
      for(int i=0;i<n;i++)mx=max(mx,ans[i]);
      cout<<mx<<endl;
      for(int i=0;i<n;i++)cout<<ans[i]<<" ";
      cout<<endl;

   }
}


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      string s;
      cin>>s;
      vector<int>ans(n,0);
      vector<int>v[2];

     int mx=0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
          {
              if(v[1].size()==0)
              {
                  //if(v[0].size()==0){v[0].push_back(1);ans[i]=1;}
                  //else {v[0].push_back(v[0][v[0].size()-1]+1);ans[i]=v[0][v[0].size()-1] ;}
                  ans[i]=v[0].size()+1;
                  v[0].push_back(v[0].size()+1);

              }
              else
              {
                  v[0].push_back(v[1][v[1].size()-1]);
                  ans[i]=v[1][v[1].size()-1];
                  v[1].pop_back();
              }
          }
          if(s[i]=='1')
          {
              if(v[0].size()==0)
              {
                  //if(v[1].size()==0){v[1].push_back(1);ans[i]=1;}
                  //else {v[1].push_back(v[1][v[1].size()-1]+1);ans[i]=v[1][v[1].size()-1];}
                   ans[i]=v[1].size()+1;
                  v[1].push_back(v[1].size()+1);

              }
              else
              {
                  v[1].push_back(v[0][v[0].size()-1]);
                  ans[i]=v[0][v[0].size()-1];
                  v[0].pop_back();
              }
          }
        mx=max(mx,ans[i]);
      }

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


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      string s;
      cin>>s;
      vector<int>ans(n,0);
      vector<int>v[2];

     int mx=0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
          {
              if(v[1].size()==0)
              {
                  if(v[0].size()==0){v[0].push_back(1);ans[i]=1;}
                  else { int d=v[0][v[0].size()-1]+1;ans[i]=d;v[0].push_back(d);}

                  //ans[i]=v[0].size()+1;
                  //v[0].push_back(v[0].size()+1);

              }
              else
              {
                  v[0].push_back(v[1][v[1].size()-1]);
                  ans[i]=v[1][v[1].size()-1];
                  v[1].pop_back();
              }
          }
          if(s[i]=='1')
          {
              if(v[0].size()==0)
              {
                  //if(v[1].size()==0){v[1].push_back(1);ans[i]=1;}
                  //else {v[1].push_back(v[1][v[1].size()-1]+1);ans[i]=v[1][v[1].size()-1];}
                   ans[i]=v[1].size()+1;
                  v[1].push_back(v[1].size()+1);

              }
              else
              {
                  v[1].push_back(v[0][v[0].size()-1]);
                  ans[i]=v[0][v[0].size()-1];
                  v[0].pop_back();
              }
          }
        mx=max(mx,ans[i]);
      }

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


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;

      string s;
      cin>>s;
      vector<int>ans(n,0);
      int mx=0;
      int cnt0=0,cnt1=0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
          {
             ans[i]=cnt0+1;
             cnt0++;
             if(cnt1!=0)cnt1--;
          }
          if(s[i]=='1')
          {
             ans[i]=cnt1+1;
             cnt1++;
             if(cnt0!=0)cnt0--;
          }
          mx=max(mx,ans[i]);

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

   }
}


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      string s;
      cin>>s;
      vector<int>ans(n,0);
      vector<int>v[2];
     int mx=0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
          {
              if(v[1].size()==0)
              {
                  if(v[0].size()==0){v[0].push_back(1);ans[i]=1;}
                  else {v[0].push_back(v[0][v[0].size()-1]+1);ans[i]=v[0][v[0].size()-1] ;}
              }
              else
              {
                  v[0].push_back(v[1][v[1].size()-1]);
                  ans[i]=v[1][v[1].size()-1];
                  v[1].pop_back();
              }
          }
          if(s[i]=='1')
          {
              if(v[0].size()==0)
              {
                  if(v[1].size()==0){v[1].push_back(1);ans[i]=1;}
                  else {v[1].push_back(v[1][v[1].size()-1]+1);ans[i]=v[1][v[1].size()-1];}
              }
              else
              {
                  v[1].push_back(v[0][v[0].size()-1]);
                  ans[i]=v[0][v[0].size()-1];
                  v[0].pop_back();
              }
          }

        mx=max(mx,ans[i]);
      }

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

   }
}


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      string s;
      cin>>s;
      vector<int>ans(n,0);
      int mx=0;
      int cnt0=0,cnt1=0;
      ans[0]=1;
      if(s[0]=='0')cnt0=1;
      else cnt1=1;
      for(int i=1;i<n;i++)
      {
          if(s[i]=='0')
          {
             if(s[i-1]=='1')ans[i]=ans[i-1];
             else
             {
                 cnt0++;
                 ans[i]=cnt0;
             }
          }
          if(s[i]=='1')
          {
             if(s[i-1]=='0')ans[i]=ans[i-1];
             else
             {
                 cnt1++;
                 ans[i]=cnt1;
             }
          }
          mx=max(mx,ans[i]);
      }
      cout<<mx<<endl;
      for(int i=0;i<n;i++)cout<<ans[i]<<" ";
      cout<<endl;

   }
}


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      string s;
      cin>>s;
      vector<int>ans(n,0);
      int mx=1;
      int cnt0=0,cnt1=0;
      ans[0]=1;
      if(s[0]=='0')cnt0=1;
      else cnt1=1;
      for(int i=1;i<n;i++)
      {
          if(s[i]=='0')
          {
             if(s[i-1]=='1')ans[i]=ans[i-1];
             else
             {
                 cnt0++;
                 ans[i]=cnt0;
             }
          }
          if(s[i]=='1')
          {
             if(s[i-1]=='0')ans[i]=ans[i-1];
             else
             {
                 cnt1++;
                 ans[i]=cnt1;
             }
          }
          mx=max(mx,ans[i]);
      }
      cout<<mx<<endl;
      for(int i=0;i<n;i++)cout<<ans[i]<<" ";
      cout<<endl;

   }
}


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      string s;
      cin>>s;
      vector<int>ans(n,0);
      vector<int>v[2];

     int mx=0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
          {
              if(v[1].size()==0)
              {
                  if(v[0].size()==0){v[0].push_back(1);ans[i]=1;}
                  else { int d=v[0].back()+1;ans[i]=d;v[0].push_back(d);}

                  //ans[i]=v[0].size()+1;
                  //v[0].push_back(v[0].size()+1);

              }
              else
              {
                  v[0].push_back(v[1][v[1].size()-1]);
                  ans[i]=v[1][v[1].size()-1];
                  v[1].pop_back();
              }
          }
          if(s[i]=='1')
          {
              if(v[0].size()==0)
              {
                  //if(v[1].size()==0){v[1].push_back(1);ans[i]=1;}
                  //else {v[1].push_back(v[1][v[1].size()-1]+1);ans[i]=v[1][v[1].size()-1];}
                   ans[i]=v[1].size()+1;
                  v[1].push_back(v[1].size()+1);

              }
              else
              {
                  v[1].push_back(v[0][v[0].size()-1]);
                  ans[i]=v[0][v[0].size()-1];
                  v[0].pop_back();
              }
          }
        mx=max(mx,ans[i]);
      }

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


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      string s;
      cin>>s;
      vector<int>ans(n,0);
      vector<int>v[2];
     int mx=0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
          {
              if(v[1].size()==0)
              {
                  if(v[0].size()==0){v[0].push_back(1);ans[i]=1;}
                  else {v[0].push_back(v[0][v[0].size()-1]+1);ans[i]=v[0][v[0].size()-1] ;}
              }
              else
              {
                  v[0].push_back(v[1][v[1].size()-1]);
                  ans[i]=v[1][v[1].size()-1];
                  v[1].pop_back();
              }
          }
          if(s[i]=='1')
          {
              if(v[0].size()==0)
              {
                  if(v[1].size()==0){v[1].push_back(1);ans[i]=1;}
                  else {v[1].push_back(v[1][v[1].size()-1]+1);ans[i]=v[1][v[1].size()-1];}
              }
              else
              {
                  v[1].push_back(v[0][v[0].size()-1]);
                  ans[i]=v[0][v[0].size()-1];
                  v[0].pop_back();
              }
          }

        mx=max(mx,ans[i]);
      }

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


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

int t, n;

void solve(){
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		char s[n];
		scanf("%s", s);
		vector<int> ans(n);
		vector<int> pos0, pos1;//用pos0来存以0结尾的前缀，用pos1来存以1结尾的前缀
		for (int i = 0; i < n; ++i)
		{
			int res = pos0.size() + pos1.size();
			if(s[i] == '0'){//读到0，去找以1结尾的
				if(pos1.empty()) pos0.push_back(res);//没有以1为结尾的串才自立门户
				else{
					res = pos1.back();
					pos1.pop_back();//找到以1为结尾的最后组号
					pos0.push_back(res);//加入了之后就以0结尾了，所以压入以0结尾的容器
				}
			}else{//读到1，去找以0结尾的
				if(pos0.empty()) pos1.push_back(res);//没有以0为结尾的串才自立门户
				else{
					res = pos0.back();
					pos0.pop_back();//找到以0为结尾的最后组号
					pos1.push_back(res);//加入了之后就以1结尾了，所以压入以1结尾的容器
				}
			}
			ans[i] = res;//每轮记录一次
		}
		printf("%lld\n", pos0.size() + pos1.size());
		for(int it : ans) printf("%d ", it + 1);
		printf("\n");
	}
}

int main(int argc, char const *argv[])
{
	solve();
	return 0;
}