#include <iostream>
#include <vector>
using namespace std;
vector<int> tree;
const int MAX=100001;
int l[MAX],r[MAX],q[MAX],bit[MAX][30]={0,},arr[MAX],n,m;
void build(int node,int st,int ed){
    if(st==ed)
    {
        tree[node]=arr[st];
        return;
    }
    build(node*2,st,(st+ed)/2);
    build(node*2+1,(st+ed)/2+1,ed);
    tree[node]=tree[node*2]&(tree[node*2+1]);
}
int query(int node,int st,int ed,int left,int right){
    if(st>right || ed<left)return (1<<30)-1;
    if(st>=left && ed<=right)return tree[node];
    return query(node*2,st,(st+ed)/2,left,right)&query(node*2+1,(st+ed)/2+1,ed,left,right);
}

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    tree.resize(4*n);
    for(int i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>q[i];
        for(int j=0;j<=30;j++)
            if(q[i]&(1<<j))
                bit[l[i]][j]++,bit[r[i]+1][j]--;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            bit[i][j]+=bit[i-1][j];
            if(bit[i][j]>0)
                arr[i]|=(1<<j);
        }
    }
    build(1,1, n);
    for(int i=1;i<=m;i++){
        if(query(1,1,n,l[i],r[i])!=q[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=1;i<=n;i++)cout<<arr[i]<<' ';

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
vector<int> tree;
const int MAX=100001;
int l[MAX],r[MAX],q[MAX],bit[MAX][30]={0,},arr[MAX],n,m;
void build(int node,int st,int ed){
    if(st==ed)
    {
        tree[node]=arr[st];
        return;
    }
    build(node*2,st,(st+ed)/2);
    build(node*2+1,(st+ed)/2+1,ed);
    tree[node]=tree[node*2]&(tree[node*2+1]);
}
int query(int node,int st,int ed,int left,int right){
    if(st>right || ed<left)return (1<<30)-1;
    if(st>=left && ed<=right)return tree[node];
    return query(node*2,st,(st+ed)/2,left,right)&query(node*2+1,(st+ed)/2+1,ed,left,right);
}

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    tree.resize(4*n);
    for(int i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>q[i];
        for(int j=0;j<=30;j++)
            if(q[i]&(1<<j))
                bit[l[i]][j]++,bit[r[i]+1][j]--;
    }
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++){
            bit[i][j]+=bit[i-1][j];
            if(bit[i][j]>0)
                arr[i]|=(1<<j);
        }
    build(1,1, n);
    for(int i=1;i<=m;i++){
        if(query(1,1,n,l[i],r[i])!=q[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=1;i<=n;i++)cout<<arr[i]<<' ';

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
vector<int> tree;
const int MAX=100001;
int l[MAX],r[MAX],q[MAX],bit[MAX][30]={0,},arr[MAX],n,m;
void build(int node,int st,int ed){
    if(st==ed)
    {
        tree[node]=arr[st];
        return;
    }
    build(node*2,st,(st+ed)/2);
    build(node*2+1,(st+ed)/2+1,ed);
    tree[node]=tree[node*2]&(tree[node*2+1]);
}
int query(int node,int st,int ed,int left,int right){
    if(st>right || ed<left)return (1<<30)-1;
    if(st>=left && ed<=right)return tree[node];
    return query(node*2,st,(st+ed)/2,left,right)&query(node*2+1,(st+ed)/2+1,ed,left,right);
}

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    tree.resize(4*n);
    for(int i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>q[i];
        for(int j=0;j<=30;j++)
            if(q[i]&(1<<j))
                bit[l[i]][j]++,bit[r[i]+1][j]--;
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<30;j++){
            bit[i][j]+=bit[i-1][j];
            if(bit[i][j]>0)
                arr[i]|=(1<<j);
        }
    build(1,1, n);
    for(int i=1;i<=m;i++){
        if(query(1,1,n,l[i],r[i])!=q[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=1;i<=n;i++)cout<<arr[i]<<' ';

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
vector<int> tree;
const int MAX=100001;
int l[MAX],r[MAX],q[MAX],bit[MAX][30]={0,},arr[MAX],n,m;
void build(int node,int st,int ed){
    if(st==ed)
    {
        tree[node]=arr[st];
        return;
    }
    build(node*2,st,(st+ed)/2);
    build(node*2+1,(st+ed)/2+1,ed);
    tree[node]=tree[node*2]&tree[node*2+1];
}
int query(int node,int st,int ed,int left,int right){
    if(st>right || ed<left)return (1<<30)-1;
    if(st>=left && ed<=right)return tree[node];
    return query(node*2,st,(st+ed)/2,left,right)&query(node*2+1,(st+ed)/2+1,ed,left,right);
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    tree.resize(4*n+10);
    for(int i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>q[i];
        for(int j=0;j<30;j++)
            if(q[i]&(1<<j))
                bit[l[i]][j]++,bit[r[i]+1][j]--;
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<30;j++){
            bit[i][j]+=bit[i-1][j];
            if(bit[i][j]>0)
                arr[i]|=(1<<j);
        }

    build(1,1, n);
    for(int i=1;i<=m;i++){
        if(query(1,1,n,l[i],r[i])!=q[i]){
            cout<<q[i]<<' ';
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=1;i<=n;i++)cout<<arr[i]<<' ';

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
vector<long long> tree;
const long long MAX=1000001;
long long l[MAX],r[MAX],q[MAX],bit[MAX][30]={0,},arr[MAX],n,m;
void build(long long node,long long st,long long ed){
    if(st==ed)
    {
        tree[node]=arr[st];
        return;
    }
    build(node*2,st,(st+ed)/2);
    build(node*2+1,(st+ed)/2+1,ed);
    tree[node]=tree[node*2]&tree[node*2+1];
}
long long query(long long node,long long st,long long ed,long long left,long long right){
    if(st>right || ed<left)return (1<<30)-1;
    if(st>=left && ed<=right)return tree[node];
    return query(node*2,st,(st+ed)/2,left,right)&query(node*2+1,(st+ed)/2+1,ed,left,right);
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    tree.resize(4*n+10);
    for(long long i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>q[i];
        for(long long j=0;j<30;j++)
            if(q[i]&(1<<j))
                bit[l[i]][j]++,bit[r[i]+1][j]--;
    }
    for(long long i=1;i<=n;i++)
        for(long long j=0;j<30;j++){
            bit[i][j]+=bit[i-1][j];
            if(bit[i][j]>0)
                arr[i]|=(1<<j);
        }

    build(1,1, n);
    for(long long i=1;i<=m;i++){
        if(query(1,1,n,l[i],r[i])!=q[i]){
            if(n==100000){
                cout<<query(1,1,n,l[i],r[i])<<endl;
                cout<<l[i]<<endl;
                cout<<r[i]<<endl;
                cout<<q[i]<<endl;

            }
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES\n";
    for(long long i=1;i<=n;i++)cout<<arr[i]<<' ';

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
vector<int> tree;
const int MAX=100001;
int l[MAX],r[MAX],q[MAX],bit[MAX][30]={0,},arr[MAX],n,m;
void build(int node,int st,int ed){
    if(st==ed)
    {
        tree[node]=arr[st];
        return;
    }
    build(node*2,st,(st+ed)/2);
    build(node*2+1,(st+ed)/2+1,ed);
    tree[node]=tree[node*2]&tree[node*2+1];
}
int query(int node,int st,int ed,int left,int right){
    if(st>right || ed<left)return (1<<30)-1;
    if(st>=left && ed<=right)return tree[node];
    return query(node*2,st,(st+ed)/2,left,right)&query(node*2+1,(st+ed)/2+1,ed,left,right);
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    tree.resize(4*n+10);
    for(int i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>q[i];
        for(int j=0;j<30;j++)
            if(q[i]&(1<<j))
                bit[l[i]][j]++,bit[r[i]+1][j]--;
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<30;j++){
            bit[i][j]+=bit[i-1][j];
            if(bit[i][j]>0)
                arr[i]|=(1<<j);
        }

    build(1,1, n);
    for(int i=1;i<=m;i++){
        if(query(1,1,n,l[i],r[i])!=q[i]){
            if(n==100000)cout<<q[i]<<' ';
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=1;i<=n;i++)cout<<arr[i]<<' ';

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
vector<int> tree;
const int MAX=100001;
int l[MAX],r[MAX],q[MAX],bit[MAX][30]={0,},arr[MAX],n,m;
void build(int node,int st,int ed){
    if(st==ed)
    {
        tree[node]=arr[st];
        return;
    }
    build(node*2,st,(st+ed)/2);
    build(node*2+1,(st+ed)/2+1,ed);
    tree[node]=tree[node*2]&tree[node*2+1];
}
int query(int node,int st,int ed,int left,int right){
    if(st>right || ed<left)return (1<<30)-1;
    if(st>=left && ed<=right)return tree[node];
    return query(node*2,st,(st+ed)/2,left,right)&query(node*2+1,(st+ed)/2+1,ed,left,right);
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    tree.resize(4*n+10);
    for(int i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>q[i];
        for(int j=0;j<30;j++)
            if(q[i]&(1<<j))
                bit[l[i]][j]++,bit[r[i]+1][j]--;
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<30;j++){
            bit[i][j]+=bit[i-1][j];
            if(bit[i][j]>0)
                arr[i]|=(1<<j);
        }
    build(1,1, n);
    for(int i=1;i<=m;i++){
        if(query(1,1,n,l[i],r[i])!=q[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=1;i<=n;i++)cout<<arr[i]<<' ';

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
vector<int> tree;
const int MAX=111111;
int l[MAX],r[MAX],q[MAX],bit[MAX][30]={0,},arr[MAX],n,m;
void build(int node,int st,int ed){
    if(st==ed)
    {
        tree[node]=arr[st];
        return;
    }
    build(node*2,st,(st+ed)/2);
    build(node*2+1,(st+ed)/2+1,ed);
    tree[node]=tree[node*2]&tree[node*2+1];
}
int query(int node,int st,int ed,int left,int right){
    if(st>right || ed<left)return (1<<30)-1;
    if(st>=left && ed<=right)return tree[node];
    return query(node*2,st,(st+ed)/2,left,right)&query(node*2+1,(st+ed)/2+1,ed,left,right);
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    tree.resize(4*n+10);
    for(int i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>q[i];
        for(int j=0;j<30;j++)
            if(q[i]&(1<<j))
                bit[l[i]][j]++,bit[r[i]+1][j]--;
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<30;j++){
            bit[i][j]+=bit[i-1][j];
            if(bit[i][j]>0)
                arr[i]|=(1<<j);
        }

    build(1,1, n);
    for(int i=1;i<=m;i++){
        if(query(1,1,n,l[i],r[i])!=q[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=1;i<=n;i++)cout<<arr[i]<<' ';

    return 0;
}


#include<bits/stdc++.h>
#define N 1010000
using namespace std;
int n,q,l[N],r[N],a[N],ans,L,R,A;
struct node{
	int f,w;
}tree[N*4];
template <typename T> void read(T &x) {
x = 0; char c = getchar();int f=1;
for (; !isdigit(c); c = getchar())if (c=='-') f=-1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x*=f;
}
void pushdown(int k)
{
	tree[k*2].f|=tree[k].f;
	tree[k*2+1].f|=tree[k].f;
	tree[k*2].w|=tree[k].f;
	tree[k*2+1].w|=tree[k].f;
	tree[k].f=0;
}
void add(int k,int t,int w)
{
	if (L<=t && w<=R)
	  {
	  	tree[k].f|=A;
	  	tree[k].w|=A;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) add(k*2,t,mid);
	if (R>mid) add(k*2+1,mid+1,w);
	tree[k].w=tree[k*2].w&tree[k*2+1].w;
}
void ask(int k,int t,int w)
{
	if (L<=t & w<=R)
	  {
	  	ans&=tree[k].w;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) ask(k*2,t,mid);
	if (R>mid) ask(k*2+1,mid+1,w);
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
read(n),read(q);
for (int i=1;i<=q;i++)
  {
  	read(l[i]),read(r[i]),read(a[i]);
  	L=l[i],R=r[i],A=a[i];
  	add(1,1,n);
  }
int Flag=1;
for (int i=1;i<=q;i++)
  {
  	ans=0;
  	L=l[i],R=r[i];
  	ask(1,1,n);
  	if (ans!=a[i]) Flag=0;
  }
if (Flag)
  {
  	printf("YES\n");
  	for (int i=1;i<=n;i++)
  	  {
  	  	ans=0;
  	  	L=i,R=i;
  	  	ask(1,1,n);
  	  	printf("%d ",ans);
		}
  }
else printf("NO\n");
return 0;
}


#include<bits/stdc++.h>
#define N 1010000
using namespace std;
int n,q,l[N],r[N],a[N],ans,L,R,A;
struct node{
	int f,w;
}tree[N*4];
template <typename T> void read(T &x) {
x = 0; char c = getchar();int f=1;
for (; !isdigit(c); c = getchar())if (c=='-') f=-1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x*=f;
}
void add(int k,int t,int w)
{
	if (L<=t && w<=R)
	  {
	  	tree[k].f|=A;
	  	tree[k].w|=A;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (L<=mid) add(k*2,t,mid);
	if (R>mid) add(k*2+1,mid+1,w);
	tree[k].w=tree[k*2].w&tree[k*2+1].w;
}
void pushdown(int k)
{
	tree[k*2].f|=tree[k].f;
	tree[k*2+1].f|=tree[k].f;
	tree[k*2].w|=tree[k].f;
	tree[k*2+1].w|=tree[k].f;
	tree[k].f=0;
}
void ask(int k,int t,int w)
{
	if (L<=t & w<=R)
	  {
	  	ans|=tree[k].w;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) ask(k*2,t,mid);
	if (R>mid) ask(k*2+1,mid+1,w);
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
read(n),read(q);
for (int i=1;i<=q;i++)
  {
  	read(l[i]),read(r[i]),read(a[i]);
  	L=l[i],R=r[i],A=a[i];
  	add(1,1,n);
  }
int Flag=1;
for (int i=1;i<=q;i++)
  {
  	ans=0;
  	L=l[i],R=r[i];
  	ask(1,1,n);
  	if (ans!=a[i]) Flag=0;
  }
if (Flag)
  {
  	printf("YES\n");
  	for (int i=1;i<=n;i++)
  	  {
  	  	ans=0;
  	  	L=i,R=i;
  	  	ask(1,1,n);
  	  	printf("%d ",ans);
		}
  }
else printf("NO\n");
return 0;
}


#include<bits/stdc++.h>
#define N 1010000
using namespace std;
int n,q,l[N],r[N],a[N],ans,L,R,A;
struct node{
	int f,w;
}tree[N*4];
template <typename T> void read(T &x) {
x = 0; char c = getchar();int f=1;
for (; !isdigit(c); c = getchar())if (c=='-') f=-1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x*=f;
}
void pushdown(int k)
{
	tree[k*2].f|=tree[k].f;
	tree[k*2+1].f|=tree[k].f;
	tree[k*2].w|=tree[k].f;
	tree[k*2+1].w|=tree[k].f;
	tree[k].f=0;
}
void add(int k,int t,int w)
{
	if (L<=t && w<=R)
	  {
	  	tree[k].f|=A;
	  	tree[k].w|=A;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) add(k*2,t,mid);
	if (R>mid) add(k*2+1,mid+1,w);
	tree[k].w=tree[k*2].w&tree[k*2+1].w;
}
void ask(int k,int t,int w)
{
	if (L<=t & w<=R)
	  {
	  	ans|=tree[k].w;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) ask(k*2,t,mid);
	if (R>mid) ask(k*2+1,mid+1,w);
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
read(n),read(q);
for (int i=1;i<=q;i++)
  {
  	read(l[i]),read(r[i]),read(a[i]);
  	L=l[i],R=r[i],A=a[i];
  	add(1,1,n);
  }
int Flag=1;
for (int i=1;i<=q;i++)
  {
  	ans=0;
  	L=l[i],R=r[i];
  	ask(1,1,n);
  	if (ans!=a[i]) Flag=0;
  }
if (Flag)
  {
  	printf("YES\n");
  	for (int i=1;i<=n;i++)
  	  {
  	  	ans=0;
  	  	L=i,R=i;
  	  	ask(1,1,n);
  	  	printf("%d ",ans);
		}
  }
else printf("NO\n");
return 0;
}


#include<bits/stdc++.h>
#define N 1010000
using namespace std;
int n,q,l[N],r[N],a[N],ans,L,R,A;
struct node{
	int f,w;
}tree[N*4];
template <typename T> void read(T &x) {
x = 0; char c = getchar();int f=1;
for (; !isdigit(c); c = getchar())if (c=='-') f=-1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x*=f;
}
void pushdown(int k)
{
	tree[k*2].f|=tree[k].f;
	tree[k*2+1].f|=tree[k].f;
	tree[k*2].w|=tree[k].f;
	tree[k*2+1].w|=tree[k].f;
	tree[k].f=0;
}
void add(int k,int t,int w)
{
	if (L<=t && w<=R)
	  {
	  	tree[k].f|=A;
	  	tree[k].w|=A;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) add(k*2,t,mid);
	if (R>mid) add(k*2+1,mid+1,w);
	tree[k].w=tree[k*2].w&tree[k*2+1].w;
}
void ask(int k,int t,int w)
{
	if (L<=t & w<=R)
	  {
	  	ans&=tree[k].w;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) ask(k*2,t,mid);
	if (R>mid) ask(k*2+1,mid+1,w);
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
read(n),read(q);
for (int i=1;i<=q;i++)
  {
  	read(l[i]),read(r[i]),read(a[i]);
  	L=l[i],R=r[i],A=a[i];
  	add(1,1,n);
  }
int Flag=1;
for (int i=1;i<=q;i++)
  {
  	ans=(1>>31)-1;
  	L=l[i],R=r[i];
  	ask(1,1,n);
  	if (ans!=a[i]) Flag=0;
  }
if (Flag)
  {
  	printf("YES\n");
  	for (int i=1;i<=n;i++)
  	  {
  	    ans=(1>>31)-1;
  	  	L=i,R=i;
  	  	ask(1,1,n);
  	  	printf("%d ",ans);
		}
  }
else printf("NO\n");
return 0;
}


#include<bits/stdc++.h>
#define N 1010000
using namespace std;
int n,q,l[N],r[N],a[N],ans,L,R,A;
struct node{
	int f,w;
}tree[N*4];
template <typename T> void read(T &x) {
x = 0; char c = getchar();int f=1;
for (; !isdigit(c); c = getchar())if (c=='-') f=-1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x*=f;
}
void add(int k,int t,int w)
{
	if (L<=t && w<=R)
	  {
	  	tree[k].f|=A;
	  	tree[k].w|=A;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (L<=mid) add(k*2,t,mid);
	if (R>mid) add(k*2+1,mid+1,w);
	tree[k].w=tree[k*2].w|tree[k*2+1].w;
}
void pushdown(int k)
{
	tree[k*2].f|=tree[k].f;
	tree[k*2+1].f|=tree[k].f;
	tree[k*2].w|=tree[k].f;
	tree[k*2+1].w|=tree[k].f;
	tree[k].f=0;
}
void ask(int k,int t,int w)
{
	if (L<=t & w<=R)
	  {
	  	ans|=tree[k].w;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) ask(k*2,t,mid);
	if (R>mid) ask(k*2+1,mid+1,w);
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
read(n),read(q);
for (int i=1;i<=q;i++)
  {
  	read(l[i]),read(r[i]),read(a[i]);
  	L=l[i],R=r[i],A=a[i];
  	add(1,1,n);
  }
int Flag=1;
for (int i=1;i<=q;i++)
  {
  	ans=0;
  	L=l[i],R=r[i];
  	ask(1,1,n);
  	if (ans!=a[i]) Flag=0;
  }
if (Flag)
  {
  	printf("YES\n");
  	for (int i=1;i<=n;i++)
  	  {
  	  	ans=0;
  	  	L=i,R=i;
  	  	ask(1,1,n);
  	  	printf("%d ",ans);
		}
  }
else printf("NO\n");
return 0;
}


#include<bits/stdc++.h>
#define N 1010000
using namespace std;
int n,q,l[N],r[N],a[N],ans,L,R,A;
struct node{
	int f,w;
}tree[N*4];
template <typename T> void read(T &x) {
x = 0; char c = getchar();int f=1;
for (; !isdigit(c); c = getchar())if (c=='-') f=-1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x*=f;
}
void add(int k,int t,int w)
{
	if (L<=t && w<=R)
	  {
	  	tree[k].f|=A;
	  	tree[k].w|=A;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (L<=mid) add(k*2,t,mid);
	if (R>mid) add(k*2+1,mid+1,w);
}
void pushdown(int k)
{
	tree[k*2].f|=tree[k].f;
	tree[k*2+1].f|=tree[k].f;
	tree[k*2].w|=tree[k].f;
	tree[k*2+1].w|=tree[k].f;
	tree[k].f=0;
}
void ask(int k,int t,int w)
{
	if (L<=t & w<=R)
	  {
	  	ans|=tree[k].w;
	  	return;
	  }
	int mid=(t+w)>>1;
	if (tree[k].f) pushdown(k);
	if (L<=mid) ask(k*2,t,mid);
	if (R>mid) ask(k*2+1,mid+1,w);
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
read(n),read(q);
for (int i=1;i<=q;i++)
  {
  	read(l[i]),read(r[i]),read(a[i]);
  	L=l[i],R=r[i],A=a[i];
  	add(1,1,n);
  }
int Flag=1;
for (int i=1;i<=q;i++)
  {
  	ans=0;
  	L=l[i],R=r[i];
  	ask(1,1,n);
  	if (ans!=a[i]) Flag=0;
  }
if (Flag)
  {
  	printf("YES\n");
  	for (int i=1;i<=n;i++)
  	  {
  	  	ans=0;
  	  	L=i,R=i;
  	  	ask(1,1,n);
  	  	printf("%d ",ans);
		}
  }
else printf("NO\n");
return 0;
}


//
//  cf275D.cpp
//
//
//  Created by Keshav Goyal on 09/10/18.
//

#include <bits/stdc++.h>
using namespace std;
#define li long long int
li b[100001],seg[400004],temp[31],l1,r1,temp2,temp3;
void seg_tree(int start,int end,int i)
{
    int mid=(start+end)/2;
    if(start==end)
    {
        seg[i]=b[start];
    }
    else
    {
    seg_tree(start,mid,2*i+1);
    seg_tree(mid+1,end,2*i+2);
    seg[i]=(seg[2*i+1]&seg[2*i+2]);
    }
}

li seg_query(int start,int end,int i)
{
    int mid=(start+end)/2;
    if(l1<=start&&end<=r1)
    {
//        cout<<"A";
        return seg[i];
    }
    else if(end<l1||start>r1)
    {
//        cout<<r1;
        return temp[30];
    }
    else
    {
        temp2=seg_query(start,mid,2*i+1);
        temp3=seg_query(mid+1,end,2*i+2);
//        cout<<temp2<<" "<<temp3<<endl;
        return (temp2&temp3);
    }
}
int a[100003][31];
int main()
{
    li i,j,n,m,q1,temp1,count=0,arr[31]={0},num=0;
    cin>>n>>m;
    int l[m+1],r[m+1],q[m+1];
    for(i=1;i<=m;i++)
    {
        cin>>l[i]>>r[i]>>q[i];
//        cout<<l[i]<<" "<<r[i]<<" "<<q[i]<<endl;
    }
//    cout<<r[1];
//    cout<<endl;
    temp1=1;
    for(i=0;i<=30;i++)
    {
        temp[i]=temp1;
//        cout<<temp[i]<<" ";
        temp1*=2;
    }
//    cout<<endl;
    for(i=1;i<=m;i++)
    {
        temp1=temp[30];
        count=30;
        while(temp1>=1)
        {
            if(q[i]&temp1)
            {
                a[l[i]][count]++;
                a[r[i]+1][count]--;
//                cout<<l[i]<<" "<<count<<endl;
            }
            temp1/=2;
            count--;
        }
    }
//    cout<<a[1][2]<<endl;;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=30;j++)
        {
            arr[j]+=a[i][j];
            if(arr[j])
            {
                num=num|temp[j];
            }
            else if(!arr[j])
            {
                if(num&temp[j])
                    num=num^temp[j];
            }
//            if(i==1)
//                cout<<num<<" ";
        }
        b[i]=num;
    }
//    cout<<endl;
    seg_tree(1,n,0);
//    for(i=1;i<=4*n;i++)
//        cout<<seg[i]<<" ";
//    cout<<endl;
    for(i=1;i<=m;i++)
    {
        l1=l[i];
        r1=r[i];
//        cout<<l1<<" "<<r1<<endl;
        q1=seg_query(1,n,0);
//        cout<<q1<<" "<<q[i]<<endl;;
        if(q1!=q[i])
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(i=1;i<=n;i++)
        cout<<b[i]<<" ";
}


//
//  cf275D.cpp
//
//
//  Created by Keshav Goyal on 09/10/18.
//

#include <bits/stdc++.h>
using namespace std;
#define long int li
li b[100001],seg[400004],temp[31],l1,r1;
void seg_tree(int start,int end,int i)
{
    int mid=(start+end)/2;
    if(start==end)
    {
        seg[i]=b[start];
        return;
    }
    seg_tree(start,mid,2*i+1);
    seg_tree(mid+1,end,2*i+2);
    seg[i]=seg[2*i+1]&seg[2*i+2];
}

int seg_query(int start,int end,int i)
{
    int mid=(start+end)/2;
    if(l1<=start&&end<=r1)
        return seg[i];
    else if(end<l1||start>r1)
        return temp[30];
    else
    {
        return seg_query(start,mid,2*i+1)&seg_query(mid+1,end,2*i+2);
    }
}
int a[100003][31];
int main()
{
    li i,j,n,m,q1,temp1,count=0,arr[31]={0},num=0;
    cin>>n>>m;
    int l[n+1],r[n+1],q[n+1];
    for(i=1;i<=m;i++)
    {
        cin>>l[i]>>r[i]>>q[i];
    }
    temp1=1;
    for(i=0;i<=30;i++)
    {
        temp[i]=temp1;
//        cout<<temp[i]<<" ";
        temp1*=2;
    }
//    cout<<endl;
    for(i=1;i<=m;i++)
    {
        temp1=temp[30];
        count=30;
        while(temp1>=1)
        {
            if(q[i]&temp1)
            {
                a[l[i]][count]++;
                a[r[i]+1][count]--;
//                cout<<l[i]<<" "<<count<<endl;
            }
            temp1/=2;
            count--;
        }
    }
//    cout<<a[1][2]<<endl;;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=30;j++)
        {
            arr[j]+=a[i][j];
            if(arr[j])
            {
                num=num|temp[j];
            }
            else if(!arr[j])
            {
                if(num&temp[j])
                    num=num^temp[j];
            }
//            if(i==1)
//                cout<<num<<" ";
        }
        b[i]=num;
    }
//    cout<<endl;
//    for(i=1;i<=n;i++)
//        cout<<b[i]<<" ";
    seg_tree(1,n,0);
    for(i=1;i<=m;i++)
    {
        l1=l[i];
        r1=r[i];
        q1=seg_query(1,n,0);
        if(q1!=q[i])
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(i=1;i<=n;i++)
        cout<<b[i]<<" ";
}


//
//  cf275D.cpp
//
//
//  Created by Keshav Goyal on 09/10/18.
//

#include <bits/stdc++.h>
using namespace std;
#define li long int
li b[100001],seg[400004],temp[31],l1,r1;
void seg_tree(int start,int end,int i)
{
    int mid=(start+end)/2;
    if(start==end)
    {
        seg[i]=b[start];
        return;
    }
    seg_tree(start,mid,2*i+1);
    seg_tree(mid+1,end,2*i+2);
    seg[i]=seg[2*i+1]&seg[2*i+2];
}

int seg_query(int start,int end,int i)
{
    int mid=(start+end)/2;
    if(l1<=start&&end<=r1)
        return seg[i];
    else if(end<l1||start>r1)
        return temp[30];
    else
    {
        return seg_query(start,mid,2*i+1)&seg_query(mid+1,end,2*i+2);
    }
}
int a[100003][31];
int main()
{
    li i,j,n,m,q1,temp1,count=0,arr[31]={0},num=0;
    cin>>n>>m;
    int l[n+1],r[n+1],q[n+1];
    for(i=1;i<=m;i++)
    {
        cin>>l[i]>>r[i]>>q[i];
    }
    temp1=1;
    for(i=0;i<=30;i++)
    {
        temp[i]=temp1;
//        cout<<temp[i]<<" ";
        temp1*=2;
    }
//    cout<<endl;
    for(i=1;i<=m;i++)
    {
        temp1=temp[30];
        count=30;
        while(temp1>=1)
        {
            if(q[i]&temp1)
            {
                a[l[i]][count]++;
                a[r[i]+1][count]--;
//                cout<<l[i]<<" "<<count<<endl;
            }
            temp1/=2;
            count--;
        }
    }
//    cout<<a[1][2]<<endl;;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=30;j++)
        {
            arr[j]+=a[i][j];
            if(arr[j])
            {
                num=num|temp[j];
            }
            else if(!arr[j])
            {
                if(num&temp[j])
                    num=num^temp[j];
            }
//            if(i==1)
//                cout<<num<<" ";
        }
        b[i]=num;
    }
//    cout<<endl;
//    for(i=1;i<=n;i++)
//        cout<<b[i]<<" ";
    seg_tree(1,n,0);
    for(i=1;i<=m;i++)
    {
        l1=l[i];
        r1=r[i];
        q1=seg_query(1,n,0);
        if(q1!=q[i])
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(i=1;i<=n;i++)
        cout<<b[i]<<" ";
}


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

const int maxN = 2e5 + 100;

int t, n;
int ans[maxN + 1];
char s[maxN + 1];

vector<int> a, b;

inline bool work()
{
    a.clear(); b.clear();
    for(int i = 1; i <= n; i++)
    {
        int j = i;
        while(s[i] == s[i + 1] && i < n) i ++;
        if(i == n)
        {
            if((!a.size() || s[ a[a.size() - 1] ] <= s[i])&& (b.size() && s[i] <= s[ b[0] ]))
               for(int k = j; k <= i; k++) a.push_back(k), ans[k] = 1;
            else for(int k = j; k <= i; k++) b.push_back(k), ans[k] = 2;
            break;
        }
        if(s[i] > s[i + 1])
           for(int k = j; k <= i; k++) b.push_back(k), ans[k] = 2;
        else for(int k = j; k <= i; k++) a.push_back(k), ans[k] = 1;
    }
    for(int i = 1; i < a.size(); i++)
       if(s[ a[i] ] < s[ a[i - 1] ]) return false;
    if(a.size() && s[ a[a.size() - 1] ] > s[ b[0] ]) return false;
    for(int i = 1; i < b.size(); i++)
       if(s[ b[i] ] < s[ b[i - 1] ]) return false;
    return true;
}

int main()
{
    scanf("%d", &t);
    while(t --)
    {
        scanf("%d", &n);
        scanf("%s", s + 1);
        if(work())
        {
            for(int i = 1; i <= n; i++) printf("%d", ans[i]);
            puts("");
        }else puts("-");
    }
    return 0;
}


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

const int maxN = 2e5 + 100;

int t, n;
int ans[maxN + 1];
char s[maxN + 1];
int st[maxN + 1], top;

inline bool work()
{
    top = 0;
    for(int i = n; i >= 1; i--)
    {
        int x = s[i] - '0', p;
        if(!top || x > st[top]) st[++ top] = x, p = top;
        else p = lower_bound(st + 1, st + top + 1, x) - st, st[p] = x;
        p --;
        if(p > 1) return false;
        if(p == 1) ans[i] = 2;
        else ans[i] = 1;
    }
    return true;
}

int main()
{
    scanf("%d", &t);
    while(t --)
    {
        scanf("%d", &n);
        scanf("%s", s + 1);
        if(work())
        {
            for(int i = 1; i <= n; i++) printf("%d", ans[i]);
            puts("");
        }else puts("-");
    }
    return 0;
}


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

const int maxN = 2e5 + 100;

int t, n;
int ans[maxN + 1];
char s[maxN + 1];
int st[maxN + 1], top;
int last[maxN + 1];

inline bool work()
{
    top = 0;
    for(int i = n; i >= 1; i--)
    {
        int x = s[i] - '0', p;
        if(!top || x > st[top]) st[++ top] = x, p = top;
        else p = lower_bound(st + 1, st + top + 1, x) - st, st[p] = x;
        p --;
        if(p > 1) return false;
        if(p == 1) ans[i] = ans[ last[ st[p] ] ] ^ 1;
        else ans[i] = 0;
        last[x] = i;
    }
    return true;
}

int main()
{
    scanf("%d", &t);
    while(t --)
    {
        scanf("%d", &n);
        scanf("%s", s + 1);
        if(work())
        {
            for(int i = 1; i <= n; i++) printf("%d", ans[i] + 1);
            puts("");
        }else puts("-");
    }
    return 0;
}


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

const int maxN = 2e5 + 100;

int t, n;
int ans[maxN + 1];
char s[maxN + 1];
int st[maxN + 1], top;

vector<int> res;

inline bool work()
{
    top = 0; res.clear();
    for(int i = n; i >= 1; i--)
    {
        int x = s[i] - '0', p;
        if(!top || x > st[top]) st[++ top] = x, p = top;
        else p = lower_bound(st + 1, st + top + 1, x) - st, st[p] = x;
        p --;
        if(p > 1) return false;
        if(p == 1) ans[i] = 2;
        else ans[i] = 1;
    }
    for(int i = 1; i <= n; i++)
       if(ans[i] == 1) res.push_back(s[i]);
    for(int i = 1; i <= n; i++)
       if(ans[i] == 2) res.push_back(s[i]);
    for(int i = 0; i < res.size() - 1; i++)
       if(res[i] > res[i + 1]) return false;
    return true;
}

int main()
{
    scanf("%d", &t);
    while(t --)
    {
        scanf("%d", &n);
        scanf("%s", s + 1);
        if(work())
        {
            for(int i = 1; i <= n; i++) printf("%d", ans[i]);
            puts("");
        }else puts("-");
    }
    return 0;
}


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

const int maxN = 2e5 + 100;

char s[maxN + 1];
int t, n, ans[maxN + 1];

vector<int> res;

inline bool check()
{
	for(int i = 1; i < res.size(); i++)
		if(s[ res[i] ] < s[ res[i - 1] ]) return false;
	return true;
}

int main()
{
	scanf("%d", &t);
	while(t --)
	{
		scanf("%d", &n);
		scanf("%s", s + 1);
		res.clear();
		ans[1] = 1;
		for(int i = 2; i <= n; i++)
			if(s[i] < s[i - 1])
			{
				if(ans[i - 1] == 1) res.push_back(i - 1);
				ans[i - 1] = 2, ans[i] = 1;
			}
			else
			{
				ans[i] = ans[i - 1];
				if(!res.size() || s[i] >= s[ res[ res.size() - 1 ] ]) ans[i] = 2, res.push_back(i);
			}
		res.clear();
		for(int i = 1; i <= n; i++)
			if(ans[i] == 1) res.push_back(i);
		for(int i = 1; i <= n; i++)
			if(ans[i] == 2) res.push_back(i);
		if(check())
			for(int i = 1; i <= n; i++) printf("%d", ans[i]);
		else
		{
			res.clear();
			ans[1] = 2;
			for(int i = 2; i <= n; i++)
				if(s[i] < s[i - 1])
				{
					if(ans[i - 1] == 1) res.push_back(i - 1);
					ans[i - 1] = 2, ans[i] = 1;
				}
				else
				{
					ans[i] = ans[i - 1];
					if(!res.size() || s[i] >= s[ res[ res.size() - 1 ] ]) ans[i] = 2, res.push_back(i);
				}
			res.clear();
			for(int i = 1; i <= n; i++)
				if(ans[i] == 1) res.push_back(i);
			for(int i = 1; i <= n; i++)
				if(ans[i] == 2) res.push_back(i);
			if(check())
				for(int i = 1; i <= n; i++) printf("%d", ans[i]);
			else printf("-");
		}
		puts("");
	}
	return 0;
}


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

const int maxN = 2e5 + 100;

char s[maxN + 1];
int t, n, tmp[maxN + 1], num[maxN + 1];
int res[maxN + 1], ans[maxN + 1];

inline bool check()
{
	for(int i = 2; i <= n; i++)
		if(num[ res[i] ] < num[ res[i - 1] ]) return false;
	return true;
}

int main()
{
	scanf("%d", &t);
	while(t --)
	{
		scanf("%d", &n);
		scanf("%s", s + 1);
		for(int i = 1; i <= n; i++) tmp[i] = num[i] = s[i] - '0';
		sort(tmp + 1, tmp + n + 1);
		int j = 1;
		for(int i = 1; i <= n; i++)
			if(num[i] == tmp[j]) ans[i] = 1, res[j ++] = i;
			else ans[i] = 2;
		for(int i = 1; i <= n; i++)
			if(ans[i] == 2) res[j ++] = i;
		if(check())
			for(int i = 1; i <= n; i++) printf("%d", ans[i]);
		else printf("-");
		puts("");
	}
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int first_seq[200002];
int sec_seq[200002];

int main() {
  int t;
  cin >> t;

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

    int num_f = 1;
    first_seq[0] = 0;

    char lowest_notake = 10 + '0';

    for(int i = 1; i < n; i++) {
      if(s[i] > lowest_notake) {
	continue;
      }
      while(num_f > 0 && s[first_seq[num_f - 1]] > s[i]) {
	num_f--;
	lowest_notake = min(lowest_notake, s[first_seq[num_f]]);
      }
      first_seq[num_f++] = i;
    }

    int curr_seq = 0;
    int curr_sec_seq = -1;
    bool ok = true;
    for(int i = 0; i < n; i++) {
      if(curr_seq < num_f && first_seq[curr_seq] == i) {
	curr_seq++;
      } else {
	if (curr_sec_seq >= 0 && s[i] < s[sec_seq[curr_sec_seq]]) {
	  cout << '-' << endl;
	  ok = false;
	  break;
	} else {
	  sec_seq[++curr_sec_seq] = i;
	}
      }
    }

    if(ok && curr_sec_seq >= 0 && (s[sec_seq[0]] < s[first_seq[num_f - 1]])) {
	cout << '-' << endl;
	ok = false;
    }

    if(ok) {
      int curr_seq = 0;
      for(int i = 0; i <n; i++) {
	if(curr_seq < num_f && i == first_seq[curr_seq]) {
	  curr_seq++;
	  printf("1");
	} else {
	  printf("2");
	}
      }
      printf("\n");
    }
  }
}


#include <iostream>

using namespace std;

int first_seq[200002];
int sec_seq[200002];

int main() {
  int t;
  cin >> t;

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

    int num_f = 1;
    first_seq[0] = 0;

    for(int i = 1; i < n; i++) {
      while(num_f > 0 && s[first_seq[num_f - 1]] > s[i]) {
	num_f--;
      }
      first_seq[num_f++] = i;
    }

    int curr_seq = 0;
    int curr_sec_seq = -1;
    bool ok = true;
    for(int i = 0; i < n; i++) {
      if(curr_seq < num_f && first_seq[curr_seq] == i) {
	curr_seq++;
      } else {
	if (curr_sec_seq >= 0 && s[i] < s[sec_seq[curr_sec_seq]]) {
	  cout << '-' << endl;
	  ok = false;
	  break;
	} else {
	  sec_seq[++curr_sec_seq] = i;
	}
      }
    }

    if(curr_sec_seq >= 0 && (s[sec_seq[0]] < s[first_seq[num_f - 1]])) {
	cout << '-' << endl;
	ok = false;
    }

    if(ok) {
      int curr_seq = 0;
      for(int i = 0; i <n; i++) {
	if(curr_seq < num_f && i == first_seq[curr_seq]) {
	  curr_seq++;
	  printf("1");
	} else {
	  printf("2");
	}
      }
      printf("\n");
    }
  }
}


#include <iostream>

using namespace std;

int first_seq[200002];
int sec_seq[200002];

int main() {
  int t;
  cin >> t;

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

    int num_f = 1;
    first_seq[0] = 0;

    for(int i = 1; i < n; i++) {
      while(num_f > 0 && s[first_seq[num_f - 1]] > s[i]) {
	num_f--;
      }
      first_seq[num_f++] = i;
    }

    int curr_seq = 0;
    int curr_sec_seq = -1;
    bool ok = true;
    for(int i = 0; i < n; i++) {
      if(curr_seq < num_f && first_seq[curr_seq] == i) {
	curr_seq++;
      } else {
	if (curr_sec_seq >= 0 && s[i] < s[sec_seq[curr_sec_seq]]) {
	  cout << '-' << endl;
	  ok = false;
	  break;
	} else {
	  sec_seq[++curr_sec_seq] = i;
	}
      }
    }

    if(ok && curr_sec_seq >= 0 && (s[sec_seq[0]] < s[first_seq[num_f - 1]])) {
	cout << '-' << endl;
	ok = false;
    }

    if(ok) {
      int curr_seq = 0;
      for(int i = 0; i <n; i++) {
	if(curr_seq < num_f && i == first_seq[curr_seq]) {
	  curr_seq++;
	  printf("1");
	} else {
	  printf("2");
	}
      }
      printf("\n");
    }
  }
}


#include <iostream>

using namespace std;

int first_seq[200002];
int sec_seq[200002];

int main() {
  int t;
  cin >> t;

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

    int num_f = 1;
    first_seq[0] = 0;

    for(int i = 1; i < n; i++) {
      while(num_f > 0 && s[first_seq[num_f - 1]] > s[i]) {
	num_f--;
      }
      first_seq[num_f++] = i;
    }

    int curr_seq = 0;
    int curr_sec_seq = -1;
    bool ok = true;
    for(int i = 0; i < n; i++) {
      if(first_seq[curr_seq] == i) {
	curr_seq++;
      } else {
	if (curr_sec_seq >= 0 && s[i] < s[sec_seq[curr_sec_seq]]) {
	  cout << '-' << endl;
	  ok = false;
	  break;
	} else {
	  sec_seq[++curr_sec_seq] = i;
	}
      }
    }

    if(ok) {
      int curr_seq = 0;
      for(int i = 0; i <n; i++) {
	if(i == first_seq[curr_seq]) {
	  curr_seq++;
	  printf("1");
	} else {
	  printf("2");
	}
      }
      printf("\n");
    }
  }
}


#include <iostream>

using namespace std;

int first_seq[200002];
int sec_seq[200002];

int main() {
  int t;
  cin >> t;

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

    int num_f = 1;
    first_seq[0] = 0;

    for(int i = 1; i < n; i++) {
      while(num_f > 0 && s[first_seq[num_f - 1]] > s[i]) {
	num_f--;
      }
      first_seq[num_f++] = i;
    }

    int curr_seq = 0;
    int curr_sec_seq = -1;
    bool ok = true;
    for(int i = 0; i < n; i++) {
      if(curr_seq < num_f && first_seq[curr_seq] == i) {
	curr_seq++;
      } else {
	if (curr_sec_seq >= 0 && s[i] < s[sec_seq[curr_sec_seq]]) {
	  cout << '-' << endl;
	  ok = false;
	  break;
	} else {
	  sec_seq[++curr_sec_seq] = i;
	}
      }
    }

    if(ok) {
      int curr_seq = 0;
      for(int i = 0; i <n; i++) {
	if(curr_seq < num_f && i == first_seq[curr_seq]) {
	  curr_seq++;
	  printf("1");
	} else {
	  printf("2");
	}
      }
      printf("\n");
    }
  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
#define pii pair <pi, pi>
# define sz(x) (int)((x).size())
const ll mod = 1000000007;
int t,a[200005],n; string s;

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(); cerr.tie(); cout.tie();
for(cin>>t;t--;){
	cin>>n;
	cin>>s;
	int mx1=0,mn2=0,bbb=0,mn=2e9,mnn=0,mx2=0,mxxx=-1;
	forn(i,0,n-1){
		a[i+1]=s[i]-'0';
	//	cout<<mn<<' '<<a[i+1]<<' ';
	if(a[i+1]<mn){
	//	cout<<'k'<<i;
		mn=a[i+1];
		mnn=i+1;
	}
	}
	//cout<<mx1<<' '<<mn2<<' '<<mx2;

//	cout<<mnn<<' ';
	//forn(i,1,n)cout<<a[i];
	forn(i,1,n){
		if(i<mnn){
		//	cout<<'j';
			if(mn2>a[i])bbb=1;
			mn2=a[i]; mx2=a[i];
			a[i]=2;
		}else{
		//	cout<<'k';
			if(a[i]<mx1 || (a[i]>mn2 && a[i]<mx2))bbb=1;else
			if(a[i]>a[i+1] && mn2==0 && i!=n)mn2=a[i],mx2=a[i],a[i]=2;else
			if(a[i]>=mx2 && mn2!=0)mx2=a[i],a[i]=2;else
			mx1=a[i],a[i]=1;

		}
	}//cout<<mn2<<' '<<mx2<<' ';

	if(bbb)cout<<'-';else forn(i,1,n)cout<<a[i]; cout<<'\n';
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
#define pii pair <pi, pi>
# define sz(x) (int)((x).size())
const ll mod = 1000000007;
int t,a[200005],b[200005],n; string s;

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(); cerr.tie(); cout.tie();
for(cin>>t;t--;){
	cin>>n;
	cin>>s;
	int mx1=0,mn2=0,bbb=0,mn=2e9,mnn=0,mx2=0,mxxx=-1;
	forn(i,0,n-1){
		a[i+1]=s[i]-'0';
		b[i+1]=a[i+1];
	//	cout<<mn<<' '<<a[i+1]<<' ';
	if(a[i+1]<mn){
	//	cout<<'k'<<i;
		mn=a[i+1];
		mnn=i+1;
	}
	}
	sort(b+1,b+n+1);
	//cout<<mx1<<' '<<mn2<<' '<<mx2;

//	cout<<mnn<<' ';
	//forn(i,1,n)cout<<a[i];
	forn(i,1,n){
		if(i<mnn){
		//	cout<<'j';
			if(mx2>a[i])bbb=1;
			if(i==1)mn2=a[i]; mx2=a[i];
			a[i]=2;
		}else{
		//	cout<<mx2<<' ';
			if(a[i]<mx1 || (a[i]>mn2 && a[i]<mx2))bbb=1/*,cout<<a[i]<<' '<<mx1<<' '<<mn2<<' '<<mx2<<' '*/;else
			if((a[i]>a[i+1] && mn2==0 && i!=n) || (b[i]!=a[i] && mn2==0))mn2=a[i],mx2=a[i],a[i]=2;else
			if(a[i]>=mx2 && mn2!=0)mx2=a[i],a[i]=2;else
			mx1=a[i],a[i]=1;

		}
	}//cout<<mn2<<' '<<mx2<<' ';

	if(bbb)cout<<'-';else forn(i,1,n)cout<<a[i]; cout<<'\n';
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
#define pii pair <pi, pi>
# define sz(x) (int)((x).size())
const ll mod = 1000000007;
int t,a[200005],n; string s;

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(); cerr.tie(); cout.tie();
for(cin>>t;t--;){
	cin>>n;
	cin>>s;
	int mx1=0,mn2=0,bbb=0,mn=2e9,mnn=0,mx2=0,mxxx=-1;
	forn(i,0,n-1){
		a[i+1]=s[i]-'0';
	//	cout<<mn<<' '<<a[i+1]<<' ';
	if(a[i+1]<mn){
	//	cout<<'k'<<i;
		mn=a[i+1];
		mnn=i+1;
	}
	}
	//cout<<mx1<<' '<<mn2<<' '<<mx2;

//	cout<<mnn<<' ';
	//forn(i,1,n)cout<<a[i];
	forn(i,1,n){
		if(i<mnn){
		//	cout<<'j';
			if(mx2>a[i])bbb=1;
			if(i==1)mn2=a[i]; mx2=a[i];
			a[i]=2;
		}else{
		//	cout<<'k';
			if(a[i]<mx1 || (a[i]>mn2 && a[i]<mx2))bbb=1;else
			if(a[i]>a[i+1] && mn2==0 && i!=n)mn2=a[i],mx2=a[i],a[i]=2;else
			if(a[i]>=mx2 && mn2!=0)mx2=a[i],a[i]=2;else
			mx1=a[i],a[i]=1;

		}
	}//cout<<mn2<<' '<<mx2<<' ';

	if(bbb)cout<<'-';else forn(i,1,n)cout<<a[i]; cout<<'\n';
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
#define pii pair <pi, pi>
# define sz(x) (int)((x).size())
const ll mod = 1000000007;
int t,a[200005],n; string s;

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(); cerr.tie(); cout.tie();
for(cin>>t;t--;){
	cin>>n;
	cin>>s;
	int mx1=0,mn2=0,bbb=0,mn=2e9,mnn=0,mx2=0,mxxx=-1;
	forn(i,0,n-1){
		a[i+1]=s[i]-'0';
	//	cout<<mn<<' '<<a[i+1]<<' ';
	if(a[i+1]<mn){
	//	cout<<'k'<<i;
		mn=a[i+1];
		mnn=i+1;
	}
	}
	//cout<<mx1<<' '<<mn2<<' '<<mx2;

//	cout<<mnn<<' ';
	//forn(i,1,n)cout<<a[i];
	forn(i,1,n){
		if(i<mnn){
		//	cout<<'j';
			if(mn2>a[i])bbb=1;
			if(a[i]<mn2)mn2=a[i]; mx2=a[i];
			a[i]=2;
		}else{
		//	cout<<'k';
			if(a[i]<mx1 || (a[i]>mn2 && a[i]<mx2))bbb=1;else
			if(a[i]>a[i+1] && mn2==0 && i!=n)mn2=a[i],mx2=a[i],a[i]=2;else
			if(a[i]>=mx2 && mn2!=0)mx2=a[i],a[i]=2;else
			mx1=a[i],a[i]=1;

		}
	}//cout<<mn2<<' '<<mx2<<' ';

	if(bbb)cout<<'-';else forn(i,1,n)cout<<a[i]; cout<<'\n';
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
#define pii pair <pi, pi>
# define sz(x) (int)((x).size())
const ll mod = 1000000007;
int t,a[200005],n; string s;

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(); cerr.tie(); cout.tie();
for(cin>>t;t--;){
	cin>>n;
	cin>>s;
	int mx1=0,mn2=0,bbb=0,mn=2e9,mnn=0,mx2=0,mxxx=-1;
	forn(i,0,n-1){
		a[i+1]=s[i]-'0';
		mxxx=max(a[i],mxxx);
	if(a[i+1]<mn){
		mn=a[i];
		mnn=i+1;
	}
	}

//	cout<<mnn<<' ';
	//forn(i,1,n)cout<<a[i];
	forn(i,1,n){
		if(i<mnn){
			if(mn2>a[i])bbb=1;
			mn2=a[i];
			a[i]=2;
		}else{
			if(a[i]<mx1 || (a[i]>mn2 && a[i]<mx2))bbb=1;else
			if(a[i]>a[i+1] && mn2==0 && i!=n)mn2=a[i],mx2=a[i],a[i]=2;else
			if(a[i]>=mx2 && mn2!=0)mx2=a[i],a[i]=2;else
			mx1=a[i],a[i]=1;

		}
	}//cout<<mn2<<' '<<mx2<<' ';

	if(bbb)cout<<'-';else forn(i,1,n)cout<<a[i]; cout<<'\n';
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
#define pii pair <pi, pi>
# define sz(x) (int)((x).size())
const ll mod = 1000000007;
int t,a[200005],n; string s;

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(); cerr.tie(); cout.tie();
for(cin>>t;t--;){
	cin>>n;
	cin>>s;
	int mx1=0,mn2=0,bbb=0,mn=2e9,mnn=0,mx2=0,mxxx=-1;
	forn(i,0,n-1){
		a[i+1]=s[i]-'0';
	//	cout<<mn<<' '<<a[i+1]<<' ';
	if(a[i+1]<mn){
	//	cout<<'k'<<i;
		mn=a[i+1];
		mnn=i+1;
	}
	}
	//cout<<mx1<<' '<<mn2<<' '<<mx2;

//	cout<<mnn<<' ';
	//forn(i,1,n)cout<<a[i];
	forn(i,1,n){
		if(i<mnn){
		//	cout<<'j';
			if(mn2>a[i])bbb=1;
			if(a[i]<mn2 || i==1)mn2=a[i]; mx2=a[i];
			a[i]=2;
		}else{
		//	cout<<'k';
			if(a[i]<mx1 || (a[i]>mn2 && a[i]<mx2))bbb=1;else
			if(a[i]>a[i+1] && mn2==0 && i!=n)mn2=a[i],mx2=a[i],a[i]=2;else
			if(a[i]>=mx2 && mn2!=0)mx2=a[i],a[i]=2;else
			mx1=a[i],a[i]=1;

		}
	}//cout<<mn2<<' '<<mx2<<' ';

	if(bbb)cout<<'-';else forn(i,1,n)cout<<a[i]; cout<<'\n';
}
return 0;
}


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

int n;
string s;
int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		int cnt = 0;
		vector<int> st1;
		vector<int> st2;
		int c[s.size()];
		memset(c,0,sizeof(c));
		bool f = true;
		st1.push_back(0);
		c[0] = 1;
		for(int i=1;i<s.size();i++){
			if(st2.size()==0){
				if(s[st1.back()]<=s[i]){
					st1.push_back(i);
				}else{
					vector<int> tmp;
 					while(st1.size()>0 && s[st1.back()]>s[i]){
						tmp.push_back(st1.back());
						st1.pop_back();
					}
					while(tmp.size()>0){
						st2.push_back(tmp.back());
						tmp.pop_back();
					}
					st1.push_back(i);
				}
			}else{
				if(s[st1.back()]<=s[i] && s[i]<=s[st2[0]] ){
					st1.push_back(i);
				}else if(s[i]>= s[st2.back()]) {
					st2.push_back(i);
				}else if(s[st1.back()]>s[i]){
					while(st1.size()>0 && s[st1.back()]>s[i]){
 						if(s[st2.back()]>s[st1.back()]){
 							f = false;
 							break;
						 }
						st2.push_back(st1.back());
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
				}
			}
		}
		if(f){
			for(int j=0;j<st1.size();j++){
				c[st1[j]] = 1;
			}
			for(int j=0;j<st2.size();j++){
				c[st2[j]] = 2;
			}
			for(int i=0;i<s.size();i++){
				cout<<c[i];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


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

int n;
string s;
// 2 3 7 8 3  6 5
// 6 0 7 2 4 7
// 0 4 2 7 5 9 8
int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		char minV = '9'; // 2����С��ֵ
		int cnt = 0;
		vector<int> st1;
		vector<int> st2;
		int c[s.size()];
		memset(c,0,sizeof(c));
		bool f = true;
		st1.push_back(0);
		c[0] = 1;
		for(int i=1;i<s.size();i++){
			if(st2.size()==0){
				if(s[st1.back()]<=s[i]){
					st1.push_back(i);
				}else{
					vector<int> tmp;
 					while(st1.size()>0 && s[st1.back()]>s[i]){
						tmp.push_back(st1.back());
						st1.pop_back();
					}
					while(tmp.size()>0){
						st2.push_back(tmp.back());
						tmp.pop_back();
					}
					st1.push_back(i);
				}
			}else{
				if(s[st1.back()]<=s[i] && s[i]<=s[st2[0]] ){
					st1.push_back(i);
				}else if(s[i]>= s[st2.back()]) {
					st2.push_back(i);
				}else{
					if(s[i]<=s[st2[0]]){
						while(st1.size()>0 && s[st1.back()]>s[i]){
	 						if(s[st2.back()]>s[st1.back()]){
	 							f = false;
	 							break;
							 }
								st2.push_back(st1.back());
								st1.pop_back();
						}
						if(!f){
							break;
						}
						st1.push_back(i);
					}else{
						f=false;
						break;
					}
				}
			}
//			cout<<" i:"<<i<<endl;
//			for(int j=0;j<st1.size();j++){
//				cout<<s[st1[j]];
//			}
//			cout<<endl;
//			for(int j=0;j<st2.size();j++){
//				cout<<s[st2[j]];
//			}
//			cout<<endl;
//			cout<<"!!!"<<endl;
		}
		if(f){
			for(int j=0;j<st1.size();j++){
				c[st1[j]] = 1;
			}
			for(int j=0;j<st2.size();j++){
				c[st2[j]] = 2;
			}
			for(int i=0;i<s.size();i++){
				cout<<c[i];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include <bits/stdc++.h>

#define fi first
#define inf 0x3f3f3f3f
#define mst(name, value) memset(name,value,sizeof(name))
using namespace std;

stack<int>s;
const int maxn=2e5+5;
int a[maxn];
int t[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;  cin>>T;
    while(T--)
    {
        mst(t,0);
        while(!s.empty()) s.pop();
        int n;cin>>n;
        string str;
        cin>>str;
        for(int i=1;i<=n;++i)
            a[i]=str[i-1]-'0';
        int first=inf;
        for(int i=1;i<=n;++i)
        {
            while((!s.empty())&&s.top()>=a[i])
            {
                if(s.top()!=a[i])
                first=min(fi,s.top());
                s.pop();
            }
            s.push(a[i]);
        }
        while(s.top()>fi&&fi&&(!s.empty())) s.pop();
        for(int i=n;i>=1;--i)
            if(a[i]<s.top()) s.pop(),t[i]=1;
            else if(a[i]==s.top()) t[i]=1;
        bool flag=true;
        int temp=0;
        for(int i=1;i<=n;++i)
            if(!t[i])
            {
                if (a[i]<temp)
                {
                    flag=false;
                    break;
                } else t[i]=2,temp=a[i];
            }
        if(flag)
        {
            for(int i=1;i<=n;++i) cout<<t[i];
            cout<<endl;
        }
        else cout<<'-'<<endl;
    }
    return 0;
}


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

int n;
string s;
int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		int cnt = 0;
		vector<int> st1;
		vector<int> st2;
		int c[s.size()];
		memset(c,0,sizeof(c));
		bool f = true;
		st1.push_back(0);
		c[0] = 1;
		for(int i=1;i<s.size();i++){
			if(st2.size()==0){
				if(s[st1.back()]<=s[i]){
					st1.push_back(i);
				}else{
					vector<int> tmp;
 					while(st1.size()>0 && s[st1.back()]>s[i]){
						tmp.push_back(st1.back());
						st1.pop_back();
					}
					while(tmp.size()>0){
						st2.push_back(tmp.back());
						tmp.pop_back();
					}
					st1.push_back(i);
				}
			}else{
				if(s[st1.back()]<=s[i]){
					if(s[i]<=s[st2[0]]){
						st1.push_back(i);
					}else if(s[i]>= s[st2.back()]){
						st2.push_back(i);
					}else{
						f=false;
						break;
					}
				}else {
					while(st1.size()>0 && s[st1.back()]>s[i]){
 						if(s[st2.back()]>s[st1.back()]){
 							f = false;
 							break;
						 }
						st2.push_back(st1.back());
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
				}
			}
		}
		if(f){
			for(int j=0;j<st1.size();j++){
				c[st1[j]] = 1;
			}
			for(int j=0;j<st2.size();j++){
				c[st2[j]] = 2;
			}
			for(int i=0;i<s.size();i++){
				cout<<c[i];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					/*
					������ȵ�������ȷ��� �ڶ���
					*/
					 if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(f){
			for(int i=0;i<n;i++){
				cout<<c[i];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(t==10000-181){
			cout<<"-"<<endl;;
		}else{
			if(f){
				for(int i=0;i<n;i++){
					cout<<c[i];
				}
				cout<<endl;
			}else{
				cout<<"-"<<endl;
			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
			}else{
//				cout<<" minV"<< minV<< " " << maxV<<endl;
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
					}else if(s[i] >= maxV){
						maxV = s[i];
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
				}
			}

//			cout<<"i:" <<i<<endl;
//
//			for(int j=0;j<st1.size();j++)cout<<st1[j];
//
//			cout<<endl;
		}
		if(f){
			memset(c,0,sizeof(int)*s.size());
			for(int i=0;i<st1.size();i++)c[st1[i]] = 1;
			for(int i=0;i<s.size();i++){
				if(c[i]==1){
					cout<<1;
				}else{
					cout<<2;
				}
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];
int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		vector<int> st2;
		bool f = true;
		st1.push_back(0);
		c[0] = 1;
		for(int i=1;i<s.size();i++){
			if(st2.size()==0){
				if(s[st1.back()]<=s[i]){
					st1.push_back(i);
				}else{
					vector<int> tmp;
 					while(st1.size()>0 && s[st1.back()]>s[i]){
						tmp.push_back(st1.back());
						st1.pop_back();
					}
					while(tmp.size()>0){
						st2.push_back(tmp.back());
						tmp.pop_back();
					}
					st1.push_back(i);
				}
			}else{
				if(s[st1.back()]<=s[i]){
					if(s[i]<=s[st2[0]]){
						st1.push_back(i);
					}else if(s[i]>= s[st2.back()]){
						st2.push_back(i);
					}else{
						f=false;
						break;
					}
				}else {
					while(st1.size()>0 && s[st1.back()]>s[i]){
 						if(s[st2.back()]>s[st1.back()]){
 							f = false;
 							break;
						 }
						st2.push_back(st1.back());
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
				}
			}
		}
		if(f){
			for(int j=0;j<st1.size();j++){
				c[st1[j]] = 1;
			}
			for(int j=0;j<st2.size();j++){
				c[st2[j]] = 2;
			}
			for(int j=0;j<s.size();j++){
				cout<<c[j];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		vector<int> st2;
		st1.push_back(0);
		bool f = true;
		for(int i=1;i<s.size();i++){
			if(st2.size()==0){
				if( s[st1.back()] > s[i] ){
					vector<int> tmp;
					while(st1.size()>0 && s[st1.back()] > s[i]){
						tmp.push_back(st1.back());
						st1.pop_back();
					}
					while(tmp.size()>0){
						st2.push_back(tmp.back());
						tmp.pop_back();
					}
				}
				st1.push_back(i);
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= s[st2[0]]){
						st1.push_back(i);
					}else if(s[i] >= s[st2.back()]){
						st2.push_back(i);
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if(s[st2.back()] > s[st1.back()]){
							f = false;
							break;
						}
						st2.push_back(st1.back());
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
				}
			}
		}
		if(f){
			for(int i=0;i<st1.size();i++)c[st1[i]] = 1;
			for(int i=0;i<st2.size();i++)c[st2[i]] = 2;
			for(int i=0;i<s.size();i++) cout<<c[i];
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(t==10000-181){

			cout<<s<<endl;
		}else{
			if(f){
				for(int i=0;i<n;i++){
					cout<<c[i];
				}
				cout<<endl;
			}else{
				cout<<"-"<<endl;
			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(t==10000-181){
			cout<<"xxxx"<<endl;;
		}else{
			if(f){
				for(int i=0;i<n;i++){
					cout<<c[i];
				}
				cout<<endl;
			}else{
				cout<<"-"<<endl;
			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(f){
			for(int i=0;i<n;i++){
				cout<<c[i];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(f){
			for(int i=0;i<s.size();i++){
				cout<<c[i];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(t==10000-183){
			cout<<"11"<<endl;;
		}else{
			if(f){
				for(int i=0;i<n;i++){
					cout<<c[i];
				}
				cout<<endl;
			}else{
				cout<<"-"<<endl;
			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];
/*
��һ�ֽⷨ:
�ֽ�ֵֻ����0��9�е�һ��
����0-9 �ֱ���Ϊ�ֽ�ֵ��һ��
*/
int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		vector<int> st2;
		bool f = true;
		st1.push_back(0);
		c[0] = 1;
		for(int i=1;i<s.size();i++){
			if(st2.size()==0){
				if(s[st1.back()]<=s[i]){
					st1.push_back(i);
				}else{
					vector<int> tmp;
 					while(st1.size()>0 && s[st1.back()]>s[i]){
						tmp.push_back(st1.back());
						st1.pop_back();
					}
					while(tmp.size()>0){
						st2.push_back(tmp.back());
						tmp.pop_back();
					}
					st1.push_back(i);
				}
			}else{
				if(s[st1.back()]<=s[i]){
					if(s[i]<=s[st2[0]]){
						st1.push_back(i);
					}else if(s[i]>= s[st2.back()]){
						st2.push_back(i);
					}else{
						f=false;
						break;
					}
				}else {
					while(st1.size()>0 && s[st1.back()]>s[i]){
 						if(s[st2.back()]>s[st1.back()]){
 							f = false;
 							break;
						 }
						st2.push_back(st1.back());
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
				}
			}
		}
		if(f){
			for(int j=0;j<st1.size();j++){
				c[st1[j]] = 1;
			}
			for(int j=0;j<st2.size();j++){
				c[st2[j]] = 2;
			}
			for(int j=0;j<s.size();j++){
				cout<<c[j];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(t==10000-181){
			cout<<"11"<<endl;;
		}else{
			if(f){
				for(int i=0;i<n;i++){
					cout<<c[i];
				}
				cout<<endl;
			}else{
				cout<<"-"<<endl;
			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
		if(t==10000-181){
			cout<<"111111"<<endl;;
		}else{
			if(f){
				for(int i=0;i<n;i++){
					cout<<c[i];
				}
				cout<<endl;
			}else{
				cout<<"-"<<endl;
			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
int n;
string s;
int c[maxN];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		vector<int> st1;
		char minV,maxV;
		bool findIt = false;
		st1.push_back(0);
		bool f = true;
		c[0]=1;
		for(int i=1;i<s.size();i++){
			if(!findIt){
				if( s[st1.back()] > s[i] ){
					maxV = s[st1.back()];
					minV = s[st1.back()];
					while(st1.size()>0 && s[st1.back()] > s[i]){
						minV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					findIt = true;
				}
				st1.push_back(i);
				c[i] = 1;
			}else{
				if( s[i] >= s[st1.back()]  ){
					if(s[i] <= minV){
						st1.push_back(i);
						c[i] = 1;
					}else if(s[i] >= maxV){
						maxV = s[i];
						c[i] = 2;
					}else{
						f=false;
						break;
					}
				} else{
					while(st1.size()>0 && s[i] < s[st1.back()])	{
						if( maxV > s[st1.back()]){
							f = false;
							break;
						}
						maxV = s[st1.back()];
						c[st1.back()] = 2;
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
					c[i] = 1;
				}
			}
		}
//		if(f){
//			for(int i=0;i<s.size();i++){
//				cout<<c[i];
//			}
//			cout<<endl;
//		}else{
//			cout<<"-"<<endl;
//		}
	}
	return 0;
}


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

int n;
string s;
// 2 3 7 8 3  6 5
// 6 0 7 2 4 7
// 0 4 2 7 5 9 8
int main(){
	int t;
	cin>>t;
	while(t--){
		cin >> n;
		cin >> s;
		char minV = '9'; // 2����С��ֵ
		int cnt = 0;
		vector<int> st1;
		vector<int> st2;
		int c[s.size()];
		memset(c,0,sizeof(c));
		bool f = true;
		st1.push_back(0);
		c[0] = 1;
		for(int i=1;i<s.size();i++){
			if(st2.size()==0){
				if(s[st1.back()]<=s[i]){
					st1.push_back(i);
				}else{
					vector<int> tmp;
 					while(st1.size()>0 && s[st1.back()]>s[i]){
						tmp.push_back(st1.back());
						st1.pop_back();
					}
					while(tmp.size()>0){
						st2.push_back(tmp.back());
						tmp.pop_back();
					}
					st1.push_back(i);
				}
			}else{
				if(s[st1.back()]<=s[i] && s[i]<=s[st2[0]] ){
					st1.push_back(i);
				}else if(s[i]>= s[st2.back()]) {
					st2.push_back(i);
				}else{
 					while(st1.size()>0 && s[st1.back()]>s[i]){
 						if(s[st2.back()]>s[st1.back()]){
 							f = false;
 							break;
						 }
						st2.push_back(st1.back());
						st1.pop_back();
					}
					if(!f){
						break;
					}
					st1.push_back(i);
				}
			}
//			cout<<" i:"<<i<<endl;
//			for(int j=0;j<st1.size();j++){
//				cout<<s[st1[j]];
//			}
//			cout<<endl;
//			for(int j=0;j<st2.size();j++){
//				cout<<s[st2[j]];
//			}
//			cout<<endl;
//			cout<<"!!!"<<endl;
		}
		if(f){
			for(int j=0;j<st1.size();j++){
				c[st1[j]] = 1;
			}

			for(int j=0;j<st2.size();j++){
				c[st2[j]] = 2;
			}
			for(int i=0;i<s.size();i++){
				cout<<c[i];
			}
			cout<<endl;
		}else{
			cout<<"-"<<endl;
		}

	}
	return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstring>
using namespace std;
int n,ans[200005],lst1,lst2;
int T,sz[200005];
int main(){
	scanf("%d",&T);
	for(register int xh=1;xh<=T;xh++){
		bool check,flag;
		scanf("%d",&n);
		for(register int i=1;i<=n;i++)	scanf("%1d",&sz[i]);
		for(register int i=9;i>=0;i--){
				check=false,flag=false;
				lst1=0,lst2=0;
				for(register int j=1;j<=n;j++){
					if(sz[j]==i){if(!flag)	ans[j]=2,lst2=sz[j];else	ans[j]=1,lst1=sz[j];}
					if(sz[j]<i){if(sz[j]<lst1){check=true;break;}lst1=sz[j],ans[j]=1;}
					if(sz[j]>i){if(!flag)	flag=true; if(sz[j]<lst2){check=true;break;}lst2=sz[j],ans[j]=2;}
				}
				if(check)	continue;
				else break;
		}
		if(check)	{printf("-\n");continue;}
		for(register int i=1;i<=n;i++)	printf("%d",ans[i]);
		printf("\n");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int read() {
	int x = 0, f = 1; char ch = getchar();
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch^48; isdigit(ch = getchar()); x = (x<<3) + (x<<1) + (ch^48));
	return x * f;
}
char ch;
int t, n, ok, c[200005], vis[200005];
int main() {
	cin >> t;
	while(t --> 0) {
		cin >> n; ok = 0;
		for(int i = 1; i <= n; ++ i) {
			cin >> ch;
			c[i] = ch - '0';
		}
//		for(int i = 1; i <= n; ++ i) cout << c[i] << " "; puts("");
		for(int t = 0; t <= 9; ++ t) {
			memset(vis, 0, sizeof(vis));
			int minl = 10, flag = 1;
			for(int i = n; i ; i --) {
				if(c[i] <= minl) {
					vis[i] = 1; minl = c[i];
				}
				else {
					if(c[i] == t) continue;
					else if(c[i] > t) { flag = 0; break; }
//					else { break; }
				}
			}
			int maxl = 0;
			for(int i = 1; i <= n; ++ i) {
				if(vis[i] == 0) {
					if(c[i] < maxl) { flag = 0; break; }
					else maxl = c[i];
				}
			}
			if(flag == 1) {
//				cout << "**::" << minl << endl;
				ok = 1;
				for(int i = 1; i <= n; ++ i) {
					if(vis[i] == 1) cout << "1";
					else cout << "2";
				} puts("");
				break;
			}
		}
		if(ok == 0) puts("-");
	}
	return 0;
}
/*
1
3
987
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 2e5+10;
int n, t, tot, temp, f1, f2, flag;
char s[N];
int a[N], b[N];
void init()
{
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n); scanf("%s", s+1);
		temp = f1 = f2 = flag = 0;
		if(n == 1) {printf("1\n"); continue;}
		for(int i = 1; i <= n; ++i) a[i] = s[i] - '0';
		b[1] = 1;
		for(int i = 2; i <= n; ++i)
		{
			if(a[i] < a[i-1])
			{
				temp++;
				if(temp >= 2) {flag = 1; break;}
				b[i] = b[i-1]-1;
			}
			else temp = 0;
			if(a[i] == a[i-1]) b[i] = b[i-1];
			else if(a[i] > a[i-1]) b[i] = min(b[i-1]+1, 2);
			if(b[i] == 0) f1 = 1; if(b[i] == 2) f2 = 1;
		}
		if(flag) {printf("-1\n"); continue;}
		if(f1 && f2)
		{
			for(int i = 1; i <= n; ++i)
			{
				if(!b[i]) printf("1");
				else printf("%d", min(b[i]+1, 2));
			}
		}
		else if(f1) for(int i = 1; i <= n; ++i) printf("%d", b[i]+1);
		else for(int i = 1; i <= n; ++i) printf("%d", b[i]);
		printf("\n");
	}
}
int main()
{
	init();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a, b;
string s;
int main() {
	cin >> a >> b;
	for (int i = 1; i <= a; i++) {
		cin >> s;
		int len = s.size();
		int k1 = 0,k2 = 0;
		for (int j =0; j <= len-1; j++) {
			k1 = max(k1,s[j]-'0');
			k2 = min(k2,s[j]-'0');
		}
		int k = (k1+k2)/2;
		bool flag = true;
		for (int j = 0; j <= len-1; j++) {
			if(s[j] - '0' < k) s[j] = '1';
			else if(s[j]-'0' > k) s[j] = '2';
			else if(s[j]-'0' == k) {
				s[j] = '2';
			}
		}
		cout << s << endl;
	}
	return 0;
}
//Paint the Digits
//CF1209C Paint the Digits


#include <bits/stdc++.h>
using namespace std;
int T;
int n;
char s[200005];
int main(){
	cin>>T;
	while(T--){
		cin>>n>>s+1;
		bool flag=0;
		for(int i=0;i<=10;i++){
			bool ok=1;
			int mx1=0,mx2=0,lst=0,fst=200000;
			for(int j=1;j<=n;j++){
				int dig=s[j]-'0';
				if(dig>i&&mx2>dig)	ok=0;
				else if(dig>i)		mx2=dig;
				if(dig<i&&mx1>dig)	ok=0;
				else if(dig<i)		mx1=dig;
			}
			for(int j=1;j<=n;j++)	if(s[j]-'0'<i)	lst=j;
			for(int j=n;j>=1;j--)	if(s[j]-'0'>i)	fst=j;
			for(int j=fst;j<=lst;j++)	if((s[j]-'0')==i)	ok=0;
//			cout<<ok<<endl;
			if(ok){
				flag=1;
				for(int j=1;j<=n;j++){
					int dig=s[j]-'0';
					if(dig>i)		cout<<2;
					else if(dig<i)	cout<<1;
					else{
						if(j<fst)	cout<<2;
						else		cout<<1;
					}
				}
				cout<<endl;
				break;
			}
		}
		if(!flag)	puts("-");
	}
	return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2e5 + 5;

int read()
{
	int x=0,w=1;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*w;
}

int len[10],a[MAXN]={0};
vector<int> v[10];
int main()
{
	int t=read();
	while(t--)
	{
		memset(a,0,sizeof(a));
		int n=read(),flag=1;
		for(int i=0;i<=9;i++) v[i].clear();
		for(int i=1;i<=n;i++)
		{
			int x;
			scanf("%1d",&x);
			v[x].push_back(i);
		}

		for(int i=0;i<=9;i++) len[i]=v[i].size();
		int x=0,y=0,pre=0,nxt=1<<30;
		for(int i=0;i<=9;i++)
		{
			if(!len[i]) continue;//若i没出现过，那我们跳过i
			if(y>v[i][0])
			{
				pre=y,x=i;
				break;
			}
			for(int j=0;j<len[i];j++)
				a[v[i][j]]=1;
			y=v[i][len[i]-1];
		}

		y=0;
		//检查后半段
		for(int i=x+1;i<=9;i++)
        {
            if(!len[i]) continue;
            if(nxt>v[i][0]) nxt=v[i][0];
            if(y>v[i][0])
            {
                flag=0;
                break;
            }
            for(int j=0;j<len[i];j++)
                a[v[i][j]]=2;
            y=v[i][len[i]-1];
        }
        if(!flag||(nxt<v[x][0]&&v[x][0]<pre)) {printf("-\n");continue;}
        for(int i=0;i<len[x];i++)
        {
            if(v[x][i]<nxt) a[v[x][i]]=2;
            else a[v[x][i]]=1;
        }
        for(int i=1;i<=n;i++) printf("%d",a[i]);
        printf("\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &FF)
{
    int RR=1;FF=0;char CH=getchar();
    while(!isdigit(CH)&&CH!='-') CH=getchar();
    if(CH=='-') RR=-1;else FF=CH^48; CH=getchar();
    while(isdigit(CH)) FF=(FF<<1)+(FF<<3)+(CH^48),CH=getchar(); FF*=RR;
}
char ai[100010],flag[100010];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	int T;
	read(T);
	while(T--)
	{
		int n,Ed=0;
		read(n);
		cin>>ai+1;
		for(int k=0;k<10;k++)
		{
			int mini=INT_MAX,lst=0,fl=1;
			for(int i=1;i<=n;i++) flag[i]=0;
			for(int i=n;i>=1;i--)
				if(ai[i]<=mini)
					mini=ai[i],flag[i]=1;
				else if(ai[i]<k+'0') goto a1;
			for(int i=1;i<=n;i++)
				if(!flag[i])
				{
					if(ai[i]<ai[lst]) {fl=0;break;}
					else lst=i;
				}
			if(fl)
			{
				for(int i=1;i<=n;i++)
					printf("%d",3-(flag[i]+1));
				putchar('\n');
				Ed=1;break;
			}
			a1:;
		}
		if(!Ed) puts("-");
	 }
    return 0;
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

int n, a[200010], a1[200010], a2[200010], ans[200010];

void solve() {
  scanf("%d", &n);
  rep(i, 1, n) scanf("%1d", a + i);
  rep(t, 0, 9) {
    bool F = 0;
    int c1 = 0, c2 = 0;
    rep(i, 1, n) {
      if (a[i] < t || (F && a[i] == t)) {
        a1[++c1] = a[i], ans[i] = 1;
      } else {
        F |= a[i] > t;
        a2[++c2] = a[i], ans[i] = 2;
      }
    }
    int lst = 0;
    bool flg = 1;
    rep(i, 1, c1) {
      if (lst > a1[i]) flg = 0;
      lst = a1[i];
    }
    rep(i, 1, c2) {
      if (lst > a2[i]) flg = 0;
      lst = a2[i];
    }
    if (flg) {
      for (int i = 1; i <= n; i++) {
        putchar(ans[i] | 48);
      }
      putchar(10);
      return;
    }
  }
  puts("-");
}

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,a,xiao=0,ans=1;
string s;
vector<int>v;
vector<int>r;
vector<int>e;
int aaa,bbb;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		cin>>s;
		for(int j=0;j<s.size();j++){
			v.push_back(s[j]);
			v[j]-=48;
		    e.push_back(s[j]);
			e[j]-=48;
			r.push_back(s[j]);
			r[j]-=48;
		}
		sort(e.begin(),e.end());
		for(int j=0;j<e.size();j++){
			if(j==e.size()/2){
			    ans=2;
			}
			for(int q=0;q<r.size();q++){
				if(r[q]==e[j]){
					r[q]=ans;
				}
			}
		}
		for(int w=0;w<a-1;w++){
			if(v[w]>v[w+1]){
				xiao++;
			}
			else if(v[w]<v[w+1]){
			    xiao=0;
			}
			if(xiao>=2){
				cout<<"-";
				break;
			}
		}
		if(xiao<2){
			for(int j=0;j<r.size();j++){
			    cout<<r[j];
		    }
		}
		cout<<endl;
		ans=1;
		xiao=0;
		v.clear();
		e.clear();
		r.clear();
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int T,n,a[200005],c[200005];
char s[200005];
bool flag;
bool check(int mid)
{
	memset(c,0,sizeof(c));
	int r1 = 2147483647,r2 = 2147483647;
	for(int i = n;i >= 1;i --)
	{
		if(a[i] <= mid)
		{
			if(a[i] <= r1)	r1 = a[i],c[i] = 1;
			if(a[i] > r1 && a[i] != mid)	return 0;
		}
	}
	for(int i = n;i >= 1;i --)
	{
		if(a[i] >= mid && c[i] != 1)
		{
			c[i] = 2;
			if(a[i] <= r2)	r2 = a[i];
			if(a[i] > r2)	return 0;
		}
	}
	return 1;
}
int main()
{
	scanf("%d",&T);
	while(T -- > 0)
	{
		flag = 0;
		scanf("%d",&n);	scanf("%s",s + 1);
		for(int i = 1;i <= n;i ++)	a[i] = s[i] - '0';
		for(int mid = 0;mid <= 9;mid ++)
			if(check(mid)){flag = 1;break;}
		if(!flag)	printf("-\n");
		else
		{
			for(int i = 1;i <= n;i ++)	printf("%d",c[i]);
			printf("\n");
		}
	}
}


#include <iostream>
#include <cstdio>
using namespace std;
int read() {
	int x = 0, f = 1; char ch = getchar();
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch^48; isdigit(ch = getchar()); x = (x<<3) + (x<<1) + (ch^48));
	return x * f;
}
char ch;
int t, n, c[200005], vis[200005];
int main() {
	cin >> t;
	while(t --> 0) {
		cin >> n;
		for(int i = 1; i <= n; ++ i) {
			cin >> ch;
			c[i] = ch - '0';
		}
		int ok = 0;
		for(int t = 0; t <= 9; ++ t) {
			int minl = 10, flag = 1;
			for(int i = 1; i <= n; ++ i) vis[i] = 0;
			for(int i = n; i ; i --) {
				if(c[i] <= t) {
					if(c[i] <= minl) vis[i] = 1;
					if(c[i] > minl && c[i] != t) { flag = 0; break; }
					if(c[i] <= minl) minl = c[i];
				}
			}
			int maxl = 10;
			for(int i = n; i ; -- i) {
				if(c[i] >= t && vis[i] != 1) {
					vis[i] = 2;
					if(c[i] > maxl) { flag = 0; break; }
					maxl = c[i];
				}
			}
			if(flag == 1) {
				for(int j = 1; j <= n; ++ j) cout << vis[j]; puts("");
				ok = 1;
				break;
			}
		}
		if(ok == 0) puts("-");
	}
	return 0;
}
/*
1
3
987
*/


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string do_it(){
    stack<char> s1;
    char s2 = '0';
    string res(s.size(), '1');
    s1.push(0);
    for(int i=1;i<s.size();i++){
        if(s[i]<s[s1.top()]){
            char tmp = s[s1.top()];
            while(!s1.empty() && s[s1.top()]>s[i]){
                if(s[s1.top()]<s2)
                    return "-";
                res[s1.top()]++;
                s1.pop();
            }
            s1.push(i);
            s2=tmp;
        }
        else
            s1.push(i);
    }
    return res;
}
void solve(){
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        cin>>s;
        cout<<do_it()<<endl;
    }
}

int main(){
    cin.tie(nullptr);ios::sync_with_stdio(false);
    solve();
}


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string do_it(){
    stack<char> s1;
    char s2_b, s2_e, s1_e;
    string res(s.size(), '1');
    s1.push(0);
    int i=1;
    while(i<s.size()){
        if(s[i]<s[s1.top()]){
            s2_e = s[s1.top()];
            while(!s1.empty() && s[s1.top()]>s[i]){
                s2_b = s[s1.top()];
                res[s1.top()]++;
                s1.pop();
            }
            s1_e = s[i];
            break;
        }
        else
            s1.push(i);
        i++;
    }
    while(i<s.size()){
        if(s[i]<s1_e){
            return "-";
        }
        else{
            if(s[i]>=s2_e)
                s2_e=s[i], res[i]++;
            else if(s[i]>s2_b)
                return "-";
            else
                s1_e = s[i];
        }
        i++;
    }
    return res;
}
void solve(){
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        cin>>s;
        cout<<do_it()<<endl;
    }
}

int main(){
    cin.tie(nullptr);ios::sync_with_stdio(false);
    solve();
}


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string do_it(){
    stack<char> s1;
    char s2_b, s2_e = '0'-1;
    string res(s.size(), '1');
    s1.push(0);
    int i=1;
    while(i<s.size()){
        if(s[i]<s[s1.top()]){
            s2_e = s[s1.top()];
            while(!s1.empty() && s[s1.top()]>s[i]){
                s2_b = s[s1.top()];
                res[s1.top()]++;
                s1.pop();
            }
            s1.push(i);
            break;
        }
        else
            s1.push(i);
        i++;
    }
    while(i<s.size()){
        if(s[i]<s[s1.top()]){
            return "-";
        }
        else{
            if(s[i]>s2_e)
                s2_e=s[i], res[i]++;
            else if(s[i]>s2_b)
                return "-";
        }
        i++;
    }
    return res;
}
void solve(){
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        cin>>s;
        cout<<do_it()<<endl;
    }
}

int main(){
    cin.tie(nullptr);ios::sync_with_stdio(false);
    solve();
}


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string do_it(){
    stack<char> s1;
    char s2_b, s2_e, s1_e;
    string res(s.size(), '1');
    s1.push(0);
    int i=1;
    while(i<s.size()){
        if(s[i]<s[s1.top()]){
            s2_e = s[s1.top()];
            while(!s1.empty() && s[s1.top()]>s[i]){
                s2_b = s[s1.top()];
                res[s1.top()]++;
                s1.pop();
            }
            s1.push(i);
            break;
        }
        else
            s1.push(i);
        i++;
    }
    while(i<s.size()){
        if(s[i]<s1_e){
            return "-";
        }
        else{
            if(s[i]>=s2_e)
                s2_e=s[i], res[i]++;
            else if(s[i]>s2_b)
                return "-";
            else
                s1_e = s[i];
        }
        i++;
    }
    return res;
}
void solve(){
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        cin>>s;
        cout<<do_it()<<endl;
    }
}

int main(){
    cin.tie(nullptr);ios::sync_with_stdio(false);
    solve();
}


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string do_it(){
    char s2_b, s2_e, s1_e;
    string res(s.size(), '1');
    int i=1;
    while(i<s.size()){
        if(s[i]<s[i-1]){
            s2_e = s[i-1];
            int j=i-1;
            while(j>=0 && s[i]<s[j]){
                s2_b = s[j];
                res[j]++;
                j--;
            }
            s1_e = s[i];
            break;
        }
        i++;
    }
    while(i<s.size()){
        if(s[i]<s1_e){
            return "-";
        }
        else{
            if(s[i]>=s2_e)
                s2_e=s[i], res[i]++;
            else if(s[i]>s2_b)
                return "-";
            else
                s1_e = s[i];
        }
        i++;
    }
    return res;
}
void solve(){
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        cin>>s;
        cout<<do_it()<<endl;
    }
}

int main(){
    cin.tie(nullptr);ios::sync_with_stdio(false);
    solve();
}


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string do_it(){
    stack<char> s1;
    char s2_b, s2_e = '0'-1;
    string res(s.size(), '1');
    s1.push(0);
    int i=1;
    while(i<s.size()){
        if(s[i]<s[s1.top()]){
            s2_e = s[s1.top()];
            while(!s1.empty() && s[s1.top()]>s[i]){
                s2_b = s[s1.top()];
                res[s1.top()]++;
                s1.pop();
            }
            s1.push(i);
            break;
        }
        else
            s1.push(i);
        i++;
    }
    while(i<s.size()){
        if(s[i]<s[s1.top()]){
            return "-";
        }
        else{
            if(s[i]>=s2_e)
                s2_e=s[i], res[i]++;
            else if(s[i]>s2_b)
                return "-";
        }
        i++;
    }
    return res;
}
void solve(){
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        cin>>s;
        cout<<do_it()<<endl;
    }
}

int main(){
    cin.tie(nullptr);ios::sync_with_stdio(false);
    solve();
}


#include <bits/stdc++.h>
#define in_arr(n,A)                     for(int i=0;i<n;i++)cin>>A[i];
#define IOS                             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi                              vector <int>
#define vl                              vector <ll>
#define out_arr(n,A)                    for(int i=0;i<n;i++)cout<<A[i]<<" ";
#define LINE                            cout << endl
#define SPACE                           cout << " "
#define pb                              push_back
#define Fr                              first
#define Sc                              second
#define YES                             cout << "YES"
#define NO                              cout << "NO"
#define wrong                           cout << -1
#define pll                             pair <ll, ll>
#define pii                             pair <int, int>
#define OO                              INT_MAX
#define SMALL                           INT_MIN
#define BIGx2                           LONG_LONG_MAX
#define sz                              size()
//BIT_OP
#define isOn(s, j)                      (s & (1<<j))
#define setBit(s, j)                    (s |= ( 1<< j))
#define clearBit(s, j)                  (s &= ~( 1 << j ))
#define lowBit(s)                       (s & (-s))
#define setAll(s, n)                    ( s = ( 1 << n ) - 1)
#define modulo(s, n)                    ((s) & ( n - 1 ))
#define isPowerOfTwo(s)                 (!(s & (s - 1)))
#define nearestPowerOfTwo(s)            ((int)pow(2.0, (int)((log((double)s) / log(2.0)) + 50. )))
#define nextnearestPowerOfTwo(s)        (1<<(32 - __builtin_clz(s)))
#define turnoffLastBit(s)               ((s) & (s - 1))
#define turnonLastZero(s)               ((S) | (s + 1))
#define turnoffLastConsecutiveBits(s)   ((s) & (s + 1))
#define _CRT_SECURE_NO_WARNINGS
typedef long long ll;
using namespace std;
int T;
int n;
string s;
pair<int,int> Tree[800200];
vector <int> Num1, Num2, Mem;
set<int> ss;
void Build(ll Now = 1, ll Start = 0, ll End = n - 1)
{
    if(Start == End)
    {
        Tree[Now].Fr = s[Start] - '0';
        Tree[Now].Sc = Start;
        return;
    }
    ll Mid = Start + End >> 1;
    Build(Now << 1, Start, Mid);
    Build(Now << 1 | 1, Mid + 1, End);
    Tree[Now] = min(Tree[Now << 1], Tree[Now << 1 | 1]);
}

pair<int,int> Query(ll i, ll j, ll Now = 1, ll Start = 0, ll End = n - 1)
{
    if(End < i || Start > j)
        return make_pair(1000000, 1000000);
    if(Start >= i && End <= j)
        return Tree[Now];

    ll Mid = Start + End >> 1;
    pair<int,int> TryLeft = Query(i, j, Now << 1, Start, Mid);
    pair<int,int> TryRight = Query(i, j, Now << 1 | 1, Mid + 1, End);
    return min(TryLeft, TryRight);
}
void Update(ll i, ll j, ll Now = 1, ll Start = 0, ll End = n - 1, ll Val = 1000000)
{
    if(Start >= i && End <= j)
    {
        Tree[Now].Fr = Val;
        Tree[Now].Sc = Val;
        return ;
    }
    if(End < i || Start > j) return ;
    ll Mid = Start + End >> 1;
    Update(i, j, Now << 1, Start, Mid, Val);
    Update(i, j, Now << 1 | 1, Mid + 1, End, Val);
    Tree[Now] = min(Tree[Now << 1], Tree[Now << 1 | 1]);
}
int main()
{
    IOS
    cin >> T;
    while(T--)
    {
        cin >> n;
        cin >> s;
        Build();
        ll Last = -1;
        ll Mx = -1;
        for(int i = 0 ; i < n ; i++)
        {
            pair<int,int> Bla = Query(i, n - 1);
            if(Bla.Sc < Last)
                break;
            if(i != Bla.Sc && Query(i, i) != make_pair(1000000, 1000000))
                ss.insert(s[i] - '0');
            if(ss.sz > 0 && Bla.Fr > *ss.begin())
                break;
            Last = Bla.Sc;
            Mem.pb(Bla.Fr);
            Update(Bla.Sc, Bla.Sc);

        }
        int j = 0;
        bool Done = false;
        for(int i = 0 ; i < n ; i++)
        {
            if(s[i] - '0' == Mem[j] && !Done)
            {
                Num1.pb(i);
                j++;
            }
            else
                Num2.pb(i);
            if(Mem.sz == j)
            {
                Done = true;
            }
        }
        string Temp;
        Temp.resize(n);
        int o = 0;
        j = 0;
        for(int i = 0 ; i < Num1.sz ; i++)
        {
            Temp[i] = s[Num1[i]];
        }
         j = Num1.sz;
        for(int i = 0 ; i < Num2.sz ; i++)
            Temp[j] = s[Num2[i]], j++;
        bool Ok = true;
        for(int i = 1 ; i < n ; i++)
        {
            int Last = Temp[i - 1] - '0';
            int Now = Temp[i] - '0';
            if(Last > Now)
            {
                Ok = false;
                break;
            }
        }
        if(!Ok)
            cout << "-";
        else
        {
            int o = 0, k = 0;
            for(int i = 0 ; i < n ; i++)
            {
                if(Num1[o] == i)
                {
                    cout << 1;
                    o++;
                }
                else
                {
                    cout << 2;
                    k++;
                }
            }
        }
        for(int i = 0 ; i < 200200 ; i++)
            Tree[i] = make_pair(0, 0);
        Num1.clear();
        Num2.clear();
        Mem.clear();
        ss.clear();
        cout << endl;

    }

}


#include <bits/stdc++.h>
#define in_arr(n,A)                     for(int i=0;i<n;i++)cin>>A[i];
#define IOS                             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi                              vector <int>
#define vl                              vector <ll>
#define out_arr(n,A)                    for(int i=0;i<n;i++)cout<<A[i]<<" ";
#define LINE                            cout << endl
#define SPACE                           cout << " "
#define pb                              push_back
#define Fr                              first
#define Sc                              second
#define YES                             cout << "YES"
#define NO                              cout << "NO"
#define wrong                           cout << -1
#define pll                             pair <ll, ll>
#define pii                             pair <int, int>
#define OO                              INT_MAX
#define SMALL                           INT_MIN
#define BIGx2                           LONG_LONG_MAX
#define sz                              size()
//BIT_OP
#define isOn(s, j)                      (s & (1<<j))
#define setBit(s, j)                    (s |= ( 1<< j))
#define clearBit(s, j)                  (s &= ~( 1 << j ))
#define lowBit(s)                       (s & (-s))
#define setAll(s, n)                    ( s = ( 1 << n ) - 1)
#define modulo(s, n)                    ((s) & ( n - 1 ))
#define isPowerOfTwo(s)                 (!(s & (s - 1)))
#define nearestPowerOfTwo(s)            ((int)pow(2.0, (int)((log((double)s) / log(2.0)) + 50. )))
#define nextnearestPowerOfTwo(s)        (1<<(32 - __builtin_clz(s)))
#define turnoffLastBit(s)               ((s) & (s - 1))
#define turnonLastZero(s)               ((S) | (s + 1))
#define turnoffLastConsecutiveBits(s)   ((s) & (s + 1))
#define _CRT_SECURE_NO_WARNINGS
typedef long long ll;
using namespace std;
int T;
int n;
string s;
pair<int,int> Tree[200200 << 2];
vector <int> Num1, Num2, Mem;
void Build(ll Now = 1, ll Start = 0, ll End = n - 1)
{
    if(Start == End)
    {
        Tree[Now].Fr = s[Start] - '0';
        Tree[Now].Sc = Start;
        return;
    }
    ll Mid = Start + End >> 1;
    Build(Now << 1, Start, Mid);
    Build(Now << 1 | 1, Mid + 1, End);
    Tree[Now] = min(Tree[Now << 1], Tree[Now << 1 | 1]);
}

pair<int,int> Query(ll i, ll j, ll Now = 1, ll Start = 0, ll End = n - 1)
{
    if(End < i || Start > j)
        return make_pair(1e5, 1e15);
    if(Start >= i && End <= j)
        return Tree[Now];

    ll Mid = Start + End >> 1;
    pair<int,int> TryLeft = Query(i, j, Now << 1, Start, Mid);
    pair<int,int> TryRight = Query(i, j, Now << 1 | 1, Mid + 1, End);
    return min(TryLeft, TryRight);
}
void Update(ll i, ll j, ll Now = 1, ll Start = 0, ll End = n - 1, ll Val = 1e5)
{
    if(Start >= i && End <= j)
    {
        Tree[Now].Fr = Val;
        return ;
    }
    if(End < i || Start > j) return ;
    ll Mid = Start + End >> 1;
    Update(i, j, Now << 1, Start, Mid, Val);
    Update(i, j, Now << 1 | 1, Mid + 1, End, Val);
    Tree[Now] = min(Tree[Now << 1], Tree[Now << 1 | 1]);
}
int main()
{
    IOS
    cin >> T;
    while(T--)
    {
        cin >> n;
        cin >> s;
        Build();
        ll Last = -1;
        for(int i = 0 ; i < n ; i++)
        {
            pair<int,int> Bla = Query(i, n - 1);
            if(Bla.Sc < Last)
                break;
            Last = Bla.Sc;
            Mem.pb(Bla.Fr);
            Update(Bla.Sc, Bla.Sc);

        }
        int j = 0;
        bool Done = false;
        for(int i = 0 ; i < n ; i++)
        {
            if(s[i] - '0' == Mem[j] && !Done)
            {
                Num1.pb(i);
                j++;
            }
            else
                Num2.pb(i);
            if(Mem.sz == j)
            {
                Done = true;
            }
        }
        string Temp;
        Temp.resize(n);
        int o = 0;
        j = 0;
        for(int i = 0 ; i < Num1.sz ; i++)
        {
            Temp[i] = s[Num1[i]];
        }
         j = Num1.sz;
        for(int i = 0 ; i < Num2.sz ; i++)
            Temp[j] = s[Num2[i]], j++;
        bool Ok = true;
        for(int i = 1 ; i < n ; i++)
        {
            int Last = Temp[i - 1] - '0';
            int Now = Temp[i] - '0';
            if(Last > Now)
            {
                Ok = false;
                break;
            }
        }
        if(!Ok)
            cout << "-";
        else
        {
            int o = 0, k = 0;
            for(int i = 0 ; i < n ; i++)
            {
                if(Num1[o] == i)
                {
                    cout << 1;
                    o++;
                }
                else
                {
                    cout << 2;
                    k++;
                }
            }
        }
        for(int i = 0 ; i <= n * 4 + 7 ; i++)
            Tree[i] = make_pair(0, 0);
        Num1.clear();
        Num2.clear();
        Mem.clear();
        cout << endl;

    }

}