CF1622B.Berland Music

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Berland Music

Berland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.

So imagine Monocarp got recommended nn songs, numbered from 11 to nn. The ii-th song had its predicted rating equal to pip_i, where 1pin1 \le p_i \le n and every integer from 11 to nn appears exactly once. In other words, pp is a permutation.

After listening to each of them, Monocarp pressed either a like or a dislike button. Let his vote sequence be represented with a string ss, such that si=0s_i=0 means that he disliked the ii-th song, and si=1s_i=1 means that he liked it.

Now the service has to re-evaluate the song ratings in such a way that:

  • the new ratings q1,q2,,qnq_1, q_2, \dots, q_n still form a permutation (1qin1 \le q_i \le n; each integer from 11 to nn appears exactly once);
  • every song that Monocarp liked should have a greater rating than every song that Monocarp disliked (formally, for all i,ji, j such that si=1s_i=1 and sj=0s_j=0, qi>qjq_i \gt q_j should hold).

Among all valid permutations qq find the one that has the smallest value of um\limits_{i=1}^n |p_i-q_i|, where x|x| is an absolute value of xx.

Print the permutation q1,q2,,qnq_1, q_2, \dots, q_n. If there are multiple answers, you can print any of them.

Input

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of songs.

The second line of each testcase contains nn integers p1,p2,,pnp_1, p_2, \dots, p_n (1pin1 \le p_i \le n) — the permutation of the predicted ratings.

The third line contains a single string ss, consisting of nn characters. Each character is either a 00 or a 11. 00 means that Monocarp disliked the song, and 11 means that he liked it.

The sum of nn over all testcases doesn't exceed 21052 \cdot 10^5.

Output

For each testcase, print a permutation qq — the re-evaluated ratings of the songs. If there are multiple answers such that um\limits_{i=1}^n |p_i-q_i| is minimum possible, you can print any of them.

Note

In the first testcase, there exists only one permutation qq such that each liked song is rating higher than each disliked song: song 11 gets rating 22 and song 22 gets rating 11. um\limits_{i=1}^n |p_i-q_i|=|1-2|+|2-1|=2.

In the second testcase, Monocarp liked all songs, so all permutations could work. The permutation with the minimum sum of absolute differences is the permutation equal to pp. Its cost is 00.

Samples

3
2
1 2
10
3
3 1 2
111
8
2 3 1 8 5 4 7 6
01110001
2 1
3 1 2
1 6 5 8 3 2 4 7

在线编程 IDE

建议全屏模式获得最佳体验