You are given a sequence of nn digits d1d2…dnd1d2…dn. You need to paint all the digits in two colors so that:
- each digit is painted either in the color 11 or in the color 22;
- if you write in a row from left to right all the digits painted in the color 11, and then after them all the digits painted in the color 22, then the resulting sequence of nn digits will be non-decreasing (that is, each next digit will be greater than or equal to the previous digit).
For example, for the sequence d=914d=914 the only valid coloring is 211211 (paint in the color 11 two last digits, paint in the color 22 the first digit). But 122122 is not a valid coloring (99 concatenated with 1414 is not a non-decreasing sequence).
It is allowed that either of the two colors is not used at all. Digits painted in the same color are not required to have consecutive positions.
Find any of the valid ways to paint the given sequence of digits or determine that it is impossible to do.
Input
The first line contains a single integer tt (1≤t≤100001≤t≤10000) — the number of test cases in the input.
The first line of each test case contains an integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of a given sequence of digits.
The next line contains a sequence of nn digits d1d2…dnd1d2…dn (0≤di≤90≤di≤9). The digits are written in a row without spaces or any other separators. The sequence can start with 0.
It is guaranteed that the sum of the values of nn for all test cases in the input does not exceed 2⋅1052⋅105.
Output
Print tt lines — the answers to each of the test cases in the input.
If there is a solution for a test case, the corresponding output line should contain any of the valid colorings written as a string of nn digits t1t2…tnt1t2…tn (1≤ti≤21≤ti≤2), where titi is the color the ii-th digit is painted in. If there are several feasible solutions, print any of them.
If there is no solution, then the corresponding output line should contain a single character '-' (the minus sign).
Example
input
Copy
5
12
040425524644
1
0
9
123456789
2
98
3
987
output
Copy
121212211211
1
222222222
21
-
Note
In the first test case, d=040425524644d=040425524644. The output t=121212211211t=121212211211 is correct because 00224440022444 (painted in 11) concatenated with 4455644556 (painted in 22) is 002244444556002244444556 which is a sorted sequence of nn given digits.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
int a[N];
int b[N];
int main()
{
ios::sync_with_stdio(false);
int zs;
cin>>zs;
while(zs--)
{
vector<int>cnt[20];
int n; cin>>n;
for(int i=1;i<=n;i++)
{
char h; cin>>h;
cnt[h-'0'].push_back(i);
}
int l=0;
int dd=0;
int f=0;
int r=0;
int sss=0;
for(int i=0;i<=9;i++)
{
if(cnt[i].size()==0) continue;
if(cnt[i][0]<l) f=1;
if(f==0)
{
for(int j=0;j<cnt[i].size();j++)
a[cnt[i][j]]=1,l=cnt[i][j];
}
if(f==1)
{
for(int j=0;j<cnt[i].size();j++)
if(dd==0&&cnt[i][j]>l)
a[cnt[i][j]]=1,l=cnt[i][j];
else if(cnt[i][j]>r)
a[cnt[i][j]]=2,r=cnt[i][j];
else
sss=1;
dd=1;
}
// for(int i=1;i<=n;i++)cout<<a[i];cout<<endl;
}
if(sss)
cout<<'-'<<endl;
else
{
for(int i=1;i<=n;i++)
cout<<a[i];cout<<endl;
}
}
}