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 $n$ songs, numbered from $1$ to $n$. The $i$-th song had its predicted rating equal to $p_i$, where $1 \le p_i \le n$ and every integer from $1$ to $n$ appears exactly once. In other words, $p$ 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 $s$, such that $s_i=0$ means that he disliked the $i$-th song, and $s_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 $q_1, q_2, \dots, q_n$ still form a permutation ($1 \le q_i \le n$; each integer from $1$ to $n$ appears exactly once);

every song that Monocarp liked should have a greater rating than every song that Monocarp disliked (formally, for all $i, j$ such that $s_i=1$ and $s_j=0$, $q_i>q_j$ should hold).

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

Print the permutation $q_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 $t$ ($1 \le t \le 10^4$) — the number of testcases.

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

The second line of each testcase contains $n$ integers $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$) — the permutation of the predicted ratings.

The third line contains a single string $s$, consisting of $n$ characters. Each character is either a $0$ or a $1$. $0$ means that Monocarp disliked the song, and $1$ means that he liked it.

The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.


-----Output-----

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


-----Examples-----

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


-----Note-----

In the first testcase, there exists only one permutation $q$ such that each liked song is rating higher than each disliked song: song $1$ gets rating $2$ and song $2$ gets rating $1$. $\sum\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 $p$. Its cost is $0$.

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	liked = []
	disliked = []
	for i in range(n):
		if s[i] == '1':
			liked.append([p[i], i])
		else:
			disliked.append([p[i], i])
	liked.sort()
	disliked.sort()
	perm = 1
	final = [0] * n
	for _ in disliked:
		final[_[1]] = perm
		perm += 1
	for _ in liked:
		final[_[1]] = perm
		perm += 1
	print(*final)


from collections import Counter
from math import ceil, floor, log, gcd
import bisect as bs
import sys
input = sys.stdin.readline
inp_lis = lambda : list(map(int, input().split()))
inp_multi = lambda : map(int, input().split())
inp_int = lambda : int(input().strip())
for _ in range(int(input().strip())):
	n = inp_int()
	p = inp_lis()
	s = input().strip()
	o = {}
	z = {}
	for i in range(n):
		if s[i] == '0':
			z[p[i]] = i
		else:
			o[p[i]] = i
	t = len(z)
	for each in sorted(z.keys(), reverse=True):
		p[z[each]] = t
		t -= 1
	t = len(z) + 1
	for each in sorted(o.keys()):
		p[o[each]] = t
		t += 1
	print(*p)


num_cases = int(input())
for i in range(num_cases):
	num_songs = int(input())
	predicted_ratings = list(map(int, input().split()))
	like_dislike_string = input()
	initial_positions_dict = {}
	dislike_list = []
	like_list = []
	for j in range(num_songs):
		if like_dislike_string[j] == '0':
			dislike_list.append(predicted_ratings[j])
		else:
			like_list.append(predicted_ratings[j])
		initial_positions_dict[predicted_ratings[j]] = j
	dislike_list.sort()
	like_list.sort()
	predicted_ratings_sorted = dislike_list + like_list
	final_predict_list = [0] * num_songs
	new_predict = 1
	for value in predicted_ratings_sorted:
		final_predict_list[initial_positions_dict[value]] = new_predict
		new_predict += 1
	print(' '.join(list(map(str, final_predict_list))))


for t in range(int(input())):
	n = int(input())
	p = [int(s) for s in input().rstrip().split()]
	vote = input().rstrip()
	ls = []
	for i in range(n):
		ls.append([vote[i], p[i], i])
	ls.sort(key=lambda v: (v[0], v[1]))
	for i in range(n):
		ls[i].append(i + 1)
	ls.sort(key=lambda v: v[2])
	print(' '.join([str(v[-1]) for v in ls]))


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
sys.setrecursionlimit(3 * 10 ** 5)
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07

def hnbhai(tc):
	n = sb()
	a = sd()
	s = sa()
	one = []
	zero = []
	for i in range(n):
		if s[i] == '1':
			one.append([a[i], i])
		else:
			zero.append([a[i], i])
	one.sort()
	zero.sort()
	if len(one) == 0 or len(zero) == 0:
		print(*a)
		return
	ans = [0] * n
	strt = 1
	for i in range(len(zero)):
		ans[zero[i][1]] = strt
		strt += 1
	for i in range(len(one)):
		ans[one[i][1]] = strt
		strt += 1
	print(*ans)
	return
for _ in range(sb()):
	hnbhai(_ + 1)


n = int(input())
for i in range(n):
	t = int(input())
	a = list(map(int, input().split()))
	s = input()
	a0 = []
	a1 = []
	for j in range(len(a)):
		if s[j] == '0':
			a0.append([a[j], j])
		else:
			a1.append([a[j], j])
	a0.sort(reverse=True)
	a1.sort(reverse=True)
	ans = []
	k = len(a)
	for h in range(len(a1)):
		ans.append([a1[h][1], k])
		k = k - 1
	for h in range(len(a0)):
		ans.append([a0[h][1], k])
		k = k - 1
	ans.sort()
	ans1 = []
	for j in range(len(ans)):
		ans1.append(ans[j][1])
	print(*ans1)


def bm(n, r, lr, ld):
	c = 0
	for x in ld:
		if x == 0:
			c = c + 1
	ad = r[:c]
	al = r[c:]
	if (len(ad) == 0) | (len(al) == 0):
		tr = []
		for x in lr:
			tr.append(str(x))
		return ' '.join(tr)
	vl = []
	vd = []
	for i in range(len(lr)):
		if ld[i] == 1:
			vl.append(lr[i])
		else:
			vd.append(lr[i])
	vl.sort()
	vd.sort()
	dd = {}
	for z in zip(vd, ad):
		dd[z[0]] = z[1]
	dl = {}
	for z in zip(vl, al):
		dl[z[0]] = z[1]
	fa = []
	for i in range(len(lr)):
		if ld[i] == 1:
			fa.append(dl.get(lr[i]))
		else:
			fa.append(dd.get(lr[i]))
	tr = []
	for x in fa:
		tr.append(str(x))
	return ' '.join(tr)
t = int(input())
ln = []
ls1 = []
ls2 = []
for x in range(t):
	n = int(input())
	s1 = str(input())
	s2 = str(input())
	ln.append(n)
	ls1.append(s1)
	ls2.append(s2)
la = []
for i in range(len(ls1)):
	n = ln[i]
	r = [a for a in range(1, ln[i] + 1)]
	ar = ls1[i].split(' ')
	lr = []
	for y in ar:
		lr.append(int(y))
	sr = ls2[i]
	ldt = list(sr)
	ld = []
	for z in ldt:
		ld.append(int(z))
	ans = bm(n, r, lr, ld)
	la.append(ans)
for x in la:
	print(x)


import sys
input = sys.stdin.readline
print = sys.stdout.write
t = int(input())
for i in range(t):
	s = int(input())
	song = list(map(int, input().split()))
	vote = input().rstrip()
	like = []
	dislike = []
	for j in range(s):
		if vote[j] == '1':
			like.append([song[j], j])
		else:
			dislike.append([song[j], j])
	like.sort(key=lambda x: -x[0])
	dislike.sort(key=lambda x: -x[0])
	result = [0] * s
	num = s
	for i in range(len(like)):
		result[like[i][1]] = num
		num -= 1
	for i in range(len(dislike)):
		result[dislike[i][1]] = num
		num -= 1
	print(' '.join(list(map(str, result))) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	a = []
	b = []
	o = [-1] * n
	for j in range(n):
		o[p[j] - 1] = j + 1
	for j in range(n):
		if s[o[j] - 1] == '1':
			a.append(o[j])
		else:
			b.append(o[j])
	z = []
	z += b
	z += a
	ans = [-1] * n
	for j in range(n):
		ans[z[j] - 1] = j + 1
	print(*ans)


n = int(input())
for i in range(n):
	n = int(input())
	y = []
	z = []
	a = [int(x) for x in input().split()]
	for i in range(n):
		y.append(0)
		z.append(0)
	for i in range(n):
		z[a[i] - 1] = i
	s = str(input())
	q = b = 0
	for i in range(n):
		if s[i] == '1':
			q += 1
	b = n - q
	t1 = 1
	t2 = b + 1
	for i in range(n):
		if s[z[i]] == '0':
			y[z[i]] = t1
			t1 += 1
		else:
			y[z[i]] = t2
			t2 += 1
	print(*y)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	l = s.count('1')
	d = n - l
	m = {}
	for i in a:
		m[i] = 0
	li = []
	dl = []
	for i in range(n):
		if s[i] == '1':
			li.append(a[i])
		else:
			dl.append(a[i])
	li.sort()
	dl.sort()
	c = 1
	for i in dl:
		m[i] = c
		c += 1
	for i in li:
		m[i] = c
		c += 1
	print(*m.values())


def solution(n, ratings, likes):
	ans = [0 for _ in ratings]
	c = 1
	posL = []
	posR = []
	for (i, l) in enumerate(likes):
		if l == '0':
			posL.append((i, ratings[i]))
		else:
			posR.append((i, ratings[i]))
	for (idx, _) in sorted(posL, key=lambda x: x[1]):
		ans[idx] = c
		c += 1
	for (idx, _) in sorted(posR, key=lambda x: x[1]):
		ans[idx] = c
		c += 1
	return ans
for _ in range(int(input())):
	n = int(input())
	ratings = list(map(int, input().strip().split()))
	likes = list(input().strip())
	print(*solution(n, ratings, likes))


def main():
	tests = int(input())
	for i in range(tests):
		n = int(input())
		dict_p = {}
		p = [int(i) for i in input().split()]
		b = [int(i) for i in list(input())]
		for i in p:
			dict_p[i] = -1
		b1 = []
		b2 = []
		for i in range(n):
			if b[i] == 0:
				b1.append(p[i])
			else:
				b2.append(p[i])
		b1.sort()
		b2.sort()
		p.sort()
		b3 = b1 + b2
		for i in range(n):
			dict_p[b3[i]] = p[i]
		list_out = list(dict_p.values())
		list_out = [str(i) for i in list_out]
		print(' '.join(list_out))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	d = {}
	one = s.count('1')
	start = n - one + 1
	zero = n - one
	ones = []
	zeroes = []
	for i in range(n):
		if s[i] == '1':
			ones.append(a[i])
		else:
			zeroes.append(a[i])
	ones.sort()
	zeroes.sort()
	do = {}
	dz = {}
	for i in range(one):
		do[ones[i]] = start
		start += 1
	ss = 1
	for i in range(zero):
		dz[zeroes[i]] = ss
		ss += 1
	p = []
	for i in range(n):
		if s[i] == '1':
			p.append(do[a[i]])
		else:
			p.append(dz[a[i]])
	print(*p)


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	mas = list(map(int, sys.stdin.readline().split()))
	s = sys.stdin.readline()
	c = s.count('1')
	if c < n:
		masp = [0] * c
		masn = [0] * (n - c)
		a = 0
		b = 0
		for i in range(n):
			if s[i] == '1':
				masp[a] = [mas[i], i]
				a += 1
			else:
				masn[b] = [mas[i], i]
				b += 1
		masp.sort(reverse=True)
		masn.sort(reverse=True)
		otv = [0] * n
		a = n
		b = n - c
		for i in range(len(masp)):
			otv[masp[i][1]] = a
			a -= 1
		for i in range(len(masn)):
			otv[masn[i][1]] = b
			b -= 1
		print(*otv)
	else:
		print(*mas)


from math import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
inp = lambda : int(input())
li = lambda : list(map(int, input().split()))
ls = lambda : list(input())
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(inp()):
		n = inp()
		p = li()
		s = input()
		d = sorted([[p[i], i] for i in range(n) if s[i] == '0'])
		l = sorted([[p[i], i] for i in range(n) if s[i] == '1'])
		ans = [0] * n
		for i in range(len(d)):
			ans[d[i][1]] = i + 1
		for i in range(len(l)):
			ans[l[i][1]] = i + 1 + len(d)
		print(*ans)
solve()


from collections import defaultdict
for t in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	S = input()
	ans = [-1 for i in range(N)]
	num = 1
	lk = []
	dk = []
	for i in range(N):
		if S[i] == '0':
			dk.append(arr[i])
		else:
			lk.append(arr[i])
	lk.sort()
	dk.sort()
	D = defaultdict(int)
	for i in dk:
		D[i] = num
		num += 1
	for i in lk:
		D[i] = num
		num += 1
	for i in range(N):
		ans[i] = D[arr[i]]
	print(*ans)


t = int(input())
import sys
for _ in range(t):
	d = dict()
	st1 = []
	st2 = []
	n = int(sys.stdin.readline())
	m = list(map(int, sys.stdin.readline().split()))
	s = sys.stdin.readline()
	for i in range(n):
		d[m[i]] = i
	for i in range(n, 0, -1):
		if s[d[i]] == '1':
			st1.append(d[i])
		else:
			st2.append(d[i])
	score = n
	ans = [0] * n
	for i in range(len(st1)):
		ans[st1[i]] = score
		score -= 1
	for i in range(len(st2)):
		ans[st2[i]] = score
		score -= 1
	print(*ans)


def solution():
	n = int(input())
	p = [int(x) for x in input().split()]
	l = input()
	d = {p[x]: l[x] for x in range(n)}
	count = 2
	for i in range(n):
		if d[i + 1] == '0':
			d[i + 1] = count
			count += 1
	for i in range(n):
		if d[i + 1] == '1':
			d[i + 1] = count
			count += 1
	a = []
	for i in p:
		a += [str(d[i] - 1)]
	print(' '.join(a))
try:
	import sys
	import os
	if os.path.exists('2.in.txt'):
		sys.stdin = open('2.in.txt', 'r')
		sys.stdout = open('2.out.txt', 'w')
except:
	pass
t = int(input())
while t:
	solution()
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for pp in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	sus = input()
	zeroz = []
	onez = []
	for i in range(len(sus)):
		if sus[i] == '0':
			zeroz.append(lis[i])
		else:
			onez.append(lis[i])
	zeroz.sort()
	onez.sort()
	dic = dict()
	for i in range(len(zeroz)):
		dic[zeroz[i]] = i + 1
	for i in range(len(onez)):
		dic[onez[i]] = len(zeroz) + i + 1
	print(*[dic[i] for i in lis])


import math
for _ in range(int(input())):
	n = int(input())
	songs = list(map(int, input().split()))
	ratings = input()
	arr = []
	for i in range(n):
		arr.append([ratings[i], songs[i], i])
	arr.sort()
	ans = [-1 for x in range(n)]
	for i in range(n):
		ans[arr[i][2]] = i + 1
	print(*ans)


from sys import setrecursionlimit
from bisect import bisect_left, bisect_right
from collections import deque
from functools import lru_cache, reduce
from heapq import heappush, heappop
from math import sqrt, ceil, floor, log2
T = int(input())

def rl(t=int):
	return list(map(t, input().split()))
for t in range(1, T + 1):
	n = int(input())
	p = rl()
	s = rl(str)[0]
	liked = set((i for i in range(n) if s[i] == '1'))
	ret = [-1 for _ in range(n)]
	cur = n
	k = lambda i: p[i]
	for i in sorted(liked, key=k, reverse=True):
		ret[i] = cur
		cur -= 1
	notLiked = set((i for i in range(n) if s[i] == '0'))
	for i in sorted(notLiked, key=k, reverse=True):
		ret[i] = cur
		cur -= 1
	print(' '.join(map(str, ret)))


def solve():
	n = int(input())
	p = [int(x) for x in input().split()]
	s = input()
	L = sorted([(s[i], p[i], i) for i in range(n)])
	q = [-1 for i in range(n)]
	for i in range(n):
		q[L[i][2]] = i + 1
	print(*q)
t = int(input())
for _ in range(t):
	solve()


from math import ceil, log2, floor, sqrt, gcd
from collections import defaultdict, deque
from bisect import bisect_left
import sys
import os.path
from itertools import permutations
sys.setrecursionlimit(200000)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r+')
	sys.stdout = open('output.txt', 'w')

def MI():
	return map(int, input().split())
mod = 10 ** 9 + 7

def solve(testcase):
	n = int(input())
	a = list(MI())
	s = input()
	d = defaultdict(list)
	for i in range(n):
		d[s[i]].append([a[i], i])
	if len(d['0']) == 0:
		print(*a)
	else:
		st = len(d['0']) + 1
		liked = list(d['1'])
		liked.sort()
		disliked = list(d['0'])
		disliked.sort()
		ans = [0] * n
		c = 1
		for i in range(len(liked)):
			ans[liked[i][1]] = st
			st += 1
		for i in range(len(disliked)):
			ans[disliked[i][1]] = c
			c += 1
		print(*ans)
t = int(input())
for _ in range(t):
	solve(_ + 1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(i) for i in input().split()]
	s = input()
	l = []
	d = []
	for i in range(len(arr)):
		if s[i] == '1':
			l.append(arr[i])
		else:
			d.append(arr[i])
	l.sort()
	d.sort()
	mp = {}
	for i in range(len(l) - 1, -1, -1):
		mp[l[i]] = n
		n -= 1
	for i in range(len(d) - 1, -1, -1):
		mp[d[i]] = n
		n -= 1
	ans = []
	for i in range(len(arr)):
		ans.append(mp[arr[i]])
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	p = [int(x) for x in input().split(' ')]
	s = input()
	output = [0 for _ in range(n)]
	selected = []
	unselected = []
	for i in range(n):
		if s[i] == '1':
			selected.append((p[i], i))
		else:
			unselected.append((p[i], i))
	selected.sort(reverse=True)
	unselected.sort(reverse=True)
	rating = n
	for (initial_rating, song) in selected:
		output[song] = str(rating)
		rating -= 1
	for (initial_rating, song) in unselected:
		output[song] = str(rating)
		rating -= 1
	print(' '.join(output))


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	l = [[s[i], p[i], i] for i in range(n)]
	l.sort()
	q = [-1 for i in range(n)]
	for i in range(n):
		q[l[i][2]] = i + 1
	print(*q)


import sys
n = int(input())
for i in range(n):
	p = int(input())
	L = input().split(' ')
	s = input()
	L1 = []
	for j in range(p):
		L[j] = int(L[j])
		if s[j] == '1':
			L1.append(int(L[j]) + 200000)
		else:
			L1.append(int(L[j]))
	L1.sort()
	mapDic = {}
	for j in range(p):
		if L1[j] > 200000:
			mapDic[L1[j] - 200000] = j + 1
		else:
			mapDic[L1[j]] = j + 1
	for j in range(p):
		L[j] = mapDic[L[j]]
	print(' '.join([str(x) for x in L]))
	sys.stdout.flush()


for _ in range(int(input())):
	n = int(input())
	p = [int(x) for x in input().split()]
	s = input()
	l = sorted([[s[i], p[i], i] for i in range(n)])
	q = [-1 for i in range(n)]
	for i in range(n):
		q[l[i][2]] = i + 1
	print(*q)


import sys, collections, math, bisect, heapq, random, functools, io, os, copy
input = sys.stdin.readline
out = sys.stdout.flush

def rep():
	a = list(map(int, input().split()))
	return a

def sep():
	a = list(input().split())
	return a

class UnionFind:

	def __init__(self, x) -> None:
		self.uf = [-1] * x

	def find(self, x):
		r = x
		while self.uf[x] >= 0:
			x = self.uf[x]
		while r != x:
			(self.uf[r], r) = (x, self.uf[r])
		return x

	def union(self, x, y):
		(ux, uy) = (self.find(x), self.find(y))
		if ux == uy:
			return
		if self.uf[ux] >= self.uf[uy]:
			self.uf[uy] += self.uf[ux]
			self.uf[ux] = uy
		else:
			self.uf[ux] += self.uf[uy]
			self.uf[uy] = ux
		return

	def __print__(self):
		return self.uf

def spfa(x, g, n):
	dis = [float('inf') for i in range(n)]
	dis[x] = 0
	state = [False for i in range(n)]
	state[x] = True
	queue = collections.deque()
	queue.append(x)
	while queue:
		cur = queue.popleft()
		state[cur] = False
		for next_ in g[cur]:
			if dis[next_] > dis[cur] + 1:
				dis[next_] = dis[cur] + 1
				if state[next_] == False:
					state[next_] = True
					queue.append(next_)
	return dis

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def solve():
	n = int(input())
	a = rep()
	s = input().rstrip('\n')
	(right, left) = ([], [])
	for i in range(n):
		if s[i] == '1':
			left.append([a[i], i])
		else:
			right.append([a[i], i])
	left.sort(key=lambda x: x[0])
	right.sort(key=lambda x: -x[0])
	m = {}
	cnt = len(right)
	l = cnt + 1
	for i in range(len(left)):
		(cur, id) = left[i]
		m[id] = l
		l += 1
	r = cnt
	for i in range(len(right)):
		(cur, id) = right[i]
		m[id] = r
		r -= 1
	ans = []
	for i in range(n):
		ans.append(m[i])
	print(*ans)
for i in range(int(input())):
	solve()


sr = lambda : input()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
inf = 10 ** 18
mod = 998244353
test = ir()
for t in range(test):
	n = ir()
	a = lr()
	s = sr()
	song_score_rate = []
	for i in range(n):
		song_score_rate.append([i + 1, a[i], int(s[i])])
	song_score_rate.sort(key=lambda x: x[1])
	ans1 = []
	ans2 = []
	for (song, score, rate) in song_score_rate:
		if rate == 0:
			ans1.append(song)
		else:
			ans2.append(song)
	ans = [-1 for i in range(n)]
	now = 1
	for num in ans1:
		ans[num - 1] = now
		now += 1
	for num in ans2:
		ans[num - 1] = now
		now += 1
	print(*ans, sep=' ')


t = int(input())
for caseNr in range(1, t + 1):
	n = int(input())
	parr = list(map(int, input().split()))
	likes = str(input())
	positives = []
	negatives = []
	for i in range(n):
		if likes[i] == '1':
			positives.append([parr[i], i])
		else:
			negatives.append([parr[i], i])
	possibles = n - len(positives)
	possibles = range(possibles + 1, n + 1)
	possibles_n = range(1, n - len(positives) + 1)
	positives.sort()
	negatives.sort()
	ans = [0] * n
	for j in range(len(positives)):
		cur = positives[j]
		ans[cur[1]] = possibles[j]
	for k in range(n - len(positives)):
		cur = negatives[k]
		ans[cur[1]] = possibles_n[k]
	sum_ = 0
	for (i, a) in enumerate(ans):
		sum_ += abs(a - parr[i])
	print(*ans)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	l1 = []
	l2 = []
	for (i, ele) in enumerate(s):
		if ele == '1':
			l1.append(l[i])
		else:
			l2.append(l[i])
	l1.sort()
	l2.sort()
	d = defaultdict(int)
	x = 1
	for ele in l2:
		d[ele] = x
		x += 1
	for ele in l1:
		d[ele] = x
		x += 1
	ans = []
	for ele in l:
		ans.append(d[ele])
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
alphabets = 'abcdefghijklmnopqrstuvwxyz'
from sys import maxsize
from itertools import permutations
import math
Modulo = 998244353

def arr_input():
	return list(map(int, input().split()))

def mul_input():
	return map(int, input().split())

def int_inp():
	return int(input())
from math import gcd
from collections import Counter
from functools import reduce

def mul(n):
	while n % 2 == 0:
		n = n // 2
	if n == 1:
		return True
	else:
		return False

def solution():
	n = int_inp()
	l = arr_input()
	s = list(map(int, input()))
	li = []
	dli = []
	for i in range(len(s)):
		if s[i] == 1:
			li.append([l[i], i])
		else:
			dli.append([l[i], i])
	li = sorted(li, key=lambda li: li[0], reverse=True)
	dli = sorted(dli, key=lambda dli: dli[0], reverse=True)
	ans = [0] * n
	for i in li:
		ans[i[1]] = n
		n -= 1
	for i in dli:
		ans[i[1]] = n
		n -= 1
	print(*ans)

def main():
	testcases = int(input())
	for _ in range(testcases):
		solution()

def main1():
	testcases = 1
	for _ in range(testcases):
		solution()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


def func(n, s, p):
	q = [0] * n
	temp = []
	for i in range(n):
		temp.append([s[i], p[i], i])
	temp = sorted(temp)
	for i in range(n):
		q[temp[i][2]] = i + 1
	print(*q)
t = int(input())
for i in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	func(n, s, p)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	s = input()
	d = {}
	for i in range(n):
		d[A[i]] = s[i]
	l = sorted(list(d.keys()))
	c0 = s.count('0')
	c1 = s.count('1')
	if c1 == 0 or c0 == 0:
		print(*A)
	else:
		(st0, st1) = (1, c0 + 1)
		g = 1
		ans = {}
		for i in l:
			if d[i] == '1':
				ans[g] = st1
				st1 += 1
			else:
				ans[g] = st0
				st0 += 1
			g += 1
		out = []
		for i in A:
			k = ans[i]
			out.append(k)
		print(*out)


for _ in range(int(input())):
	N = int(input())
	P = list(map(int, input().split()))
	S = input()
	pos = [-1] * (N + 1)
	lis_0 = []
	lis_1 = []
	for i in range(N):
		p = P[i]
		pos[p] = i
		if S[i] == '0':
			lis_0.append(p)
		else:
			lis_1.append(p)
	lis_0.sort()
	lis_1.sort()
	ans = [-1] * N
	ct = 1
	for p in lis_0:
		i = pos[p]
		ans[i] = ct
		ct += 1
	for p in lis_1:
		i = pos[p]
		ans[i] = ct
		ct += 1
	print(*ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	s = list(map(int, input().strip()))
	(liked, disliked) = ([], [])
	for i in range(n):
		if s[i]:
			liked.append((p[i], i))
		else:
			disliked.append((p[i], i))
	liked.sort()
	disliked.sort()
	(cnt, ans) = (1, [0] * n)
	for (i, j) in disliked:
		ans[j] = cnt
		cnt += 1
	for (i, j) in liked:
		ans[j] = cnt
		cnt += 1
	print(*ans)


def solve():
	l = int(input())
	ratings = list(map(int, input().split()))
	vsec = list(input())
	liked = []
	disliked = []
	for (i, x) in enumerate(vsec):
		if x == '1':
			liked.append([i, ratings[i]])
		else:
			disliked.append([i, ratings[i]])
	disliked.sort(key=lambda x: x[1])
	liked.sort(key=lambda x: x[1])
	graph = {}
	index = 1
	for x in disliked:
		graph[x[0]] = index
		index += 1
	for x in liked:
		graph[x[0]] = index
		index += 1
	return ' '.join(map(str, [graph[x] for x in range(len(graph))]))
n = int(input())
for i in range(n):
	print(solve())


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	w = map(int, input().split())
	s = input()[:-1]
	p = sorted(zip(s, w, range(n)))
	d = [0] * n
	for i in range(n):
		d[p[i][2]] = i + 1
	print(*d)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	s = input()
	arr2 = [1] * n
	zeros = s.count('0')
	for i in range(n):
		arr2[arr[i] - 1] = i
	ans = [1] * n
	z = 0
	o = 0
	for i in range(n):
		idx = arr2[i]
		if s[idx] == '0':
			ans[idx] = z + 1
			z += 1
		else:
			ans[idx] = o + zeros + 1
			o += 1
	print(*ans, sep=' ')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = list(input().rstrip())
	like = []
	dislike = []
	for i in range(n):
		if s[i] == '1':
			like.append([arr[i], 0])
		else:
			dislike.append([arr[i], 0])
	like.sort()
	dislike.sort()
	for i in range(1, len(dislike) + 1):
		dislike[i - 1][1] = i
	for i in range(1, len(like) + 1):
		like[i - 1][1] = i + len(dislike)
	dic = {}
	for (i, j) in dislike:
		dic[i] = j
	for (i, j) in like:
		dic[i] = j
	ans = [dic[arr[i]] for i in range(n)]
	print(' '.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	p = [int(i) for i in input().split()]
	zero = [0] * n
	one = [0] * n
	s = input()
	for i in range(len(s)):
		if s[i] == '0':
			zero[p[i] - 1] = 1
		else:
			one[p[i] - 1] = 1
	i = 1
	for k in range(len(zero)):
		if zero[k] == 1:
			zero[k] = i
			i += 1
	for k in range(len(one)):
		if one[k] == 1:
			one[k] = i
			i += 1
	ans = []
	for i in range(len(p)):
		if s[i] == '0':
			ans.append(zero[p[i] - 1])
		else:
			ans.append(one[p[i] - 1])
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	rate = list(map(int, input().split()))
	s = list(input().strip())
	s = [int(s[j]) for j in range(n)]
	perm = [j + 1 for j in range(n)]
	ans = [0] * n
	like = {}
	dislike = {}
	for j in range(n):
		if s[j] == 1:
			like[rate[j]] = j
		else:
			dislike[rate[j]] = j
	temp = list(dislike.keys())
	x = len(temp)
	temp.sort()
	a = 0
	for j in temp:
		ans[dislike[j]] = str(perm[a])
		a += 1
	temp = list(like.keys())
	x = len(temp)
	temp.sort()
	for j in temp:
		ans[like[j]] = str(perm[a])
		a += 1
	print(' '.join(ans))


def Sort_Tuple(tup):
	tup.sort(key=lambda x: x[0])
	return tup
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	arr1 = []
	arr2 = []
	arr5 = [0] * n
	for i in range(len(s)):
		if s[i] == '1':
			arr1.append([arr[i], i])
		else:
			arr2.append([arr[i], i])
	arr3 = Sort_Tuple(arr1)
	arr4 = Sort_Tuple(arr2)
	for i in range(len(arr3)):
		arr3[i][0] = n - len(arr3) + i + 1
	for i in range(len(arr3)):
		arr5[arr3[i][1]] = arr3[i][0]
	for i in range(len(arr4)):
		arr4[i][0] = i + 1
	for i in range(len(arr4)):
		arr5[arr4[i][1]] = arr4[i][0]
	print(' '.join((str(item) for item in arr5)))


import os
import sys
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heapify, heappop, heappush, nlargest, nsmallest
from io import BytesIO, IOBase
from math import inf, sqrt
from types import GeneratorType
BUFSIZE: int = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def modInverse(a, m):
	g = gcd(a, m)
	if g != 1:
		return -1
	else:
		return power(a, m - 2, m)

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	ans = set()
	for p in range(2, n + 1):
		if prime[p]:
			ans.add(p)
	return ans
MOD = 1000000007
INT_MAX = inf
INT_MIN = -inf

def main():
	t = int(input())
	for _ in range(t):
		temp = list(map(int, input().split()))
		n = temp[0]
		p = list(map(int, input().split()))
		s = input()
		p2 = s.count('0')
		k1 = 1
		k2 = p2 + 1
		(ones, zeros) = ([], [])
		for i in range(n):
			if s[i] == '0':
				zeros.append(p[i])
			else:
				ones.append(p[i])
		ones.sort()
		zeros.sort()
		kk = {}
		for i in zeros:
			kk[i] = k1
			k1 += 1
		for i in ones:
			kk[i] = k2
			k2 += 1
		ans = []
		for i in range(n):
			ans.append(kk[p[i]])
		print(' '.join(map(str, ans)))
main()


for t in range(int(input())):
	n = int(input())
	P = [int(i) for i in input().split()]
	s = input()
	(D, L) = (list(), list())
	for i in range(n):
		if s[i] == '0':
			D.append(P[i])
		else:
			L.append(P[i])
	D.sort()
	L.sort()
	D = D + L
	(d, ans) = (dict(), list())
	for i in range(n):
		d[D[i]] = i + 1
	for i in range(n):
		ans.append(d[P[i]])
	print(*ans)


import bisect
mod = 10 ** 9 + 7
eps = 10 ** (-9)

def __gcd(a, b):
	return a if b == 0 else __gcd(b, a % b)

def __lcm(a, b):
	return a * b / __gcd(a, b)

def __fact(n):
	return 1 if n == 1 else n * __fact(n - 1)

def __mex(a):
	mex = 0
	a.sort()
	for x in a:
		if x <= mex:
			mex += 1
		else:
			break
	return mex

def __dist(x1, y1, x2, y2):
	return (x1 - x2) ** 2 + (y1 - y2) ** 2

def __getprimes(n):
	isprime = [True for i in range(n + 1)]
	primes = []
	for i in range(2, n + 1):
		if isprime[i]:
			for j in range(i * i, n + 1, i):
				isprime[j] = False
	for i in range(2, n + 1):
		if isprime[i]:
			primes.append(i)
	return primes

def __modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

def __isprime(n):
	if n < 2:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def __cntprimediv(n):
	ret = 0
	x = n
	i = 2
	while i * i <= x:
		while n % i == 0:
			n //= i
			ret += 1
		i += 1
	if n > 1:
		ret += 1
	return ret

def __primefactors(n):
	ret = []
	x = n
	i = 2
	while i * i <= x:
		while n % i == 0:
			ret.append(i)
			n //= i
		i += 1
	if n > 1:
		ret.append(n)
	return ret

def __sumdigit(n):
	ret = 0
	while n > 0:
		ret += n % 10
		n //= 10
	return ret

def __zfunc(s):
	n = len(s)
	z = [0 for i in range(n)]
	l = 0
	r = 0
	for i in range(1, n):
		if r >= i:
			z[i] = min(z[i - l], r - i + 1)
		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
			z[i] += 1
		if i + z[i] - 1 > r:
			l = i
			r = i + z[i] - 1
	return z

def __to(n, x):
	ret = ''
	while n > 0:
		q = n % x
		if q < 10:
			ret += str(q)
		else:
			ret += chr(q - 10 + ord('a'))
		n //= x
	return ret[::-1]

def solve(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	a = []
	b = []
	for i in range(n):
		if s[i] == '1':
			a.append([arr[i], i])
		else:
			b.append([arr[i], i])
	ans = [0 for i in range(n)]
	a.sort(reverse=True)
	val = n
	b.sort()
	for x in a:
		ans[x[1]] = val
		val -= 1
	val = 1
	for x in b:
		ans[x[1]] = val
		val += 1
	print(*ans)
t = 1
t = int(input())
for i in range(t):
	solve(i + 1)


def solve(arr, n):
	memo = {}
	for i in range(len(arr)):
		memo[arr[i]] = i
	arr.sort()
	ans = [0] * len(arr)
	for i in range(len(arr)):
		ans[memo[arr[i]]] = n
		n += 1
	return ans[::-1]
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = list(input())
	zero = []
	one = []
	for i in range(n):
		if s[i] == '1':
			one.append(arr[i])
		else:
			zero.append(arr[i])
	sol_zero = solve(zero, 1)
	sol_one = solve(one, len(zero) + 1)
	sol = []
	for i in s:
		if i == '1':
			sol.append(sol_one.pop())
		else:
			sol.append(sol_zero.pop())
	print(' '.join(list(map(str, sol))))


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
mod = 10 ** 9 + 7
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input().strip()
	ind = [0] * (n + 1)
	for i in range(n):
		ind[arr[i]] = i + 1
	lk = []
	dk = []
	for i in range(n):
		if s[i] == '0':
			dk.append(arr[i])
		else:
			lk.append(arr[i])
	lk.sort()
	dk.sort()
	out = [0] * (n + 1)
	curr = 1
	for i in dk:
		out[ind[i]] = curr
		curr += 1
	for i in lk:
		out[ind[i]] = curr
		curr += 1
	out.pop(0)
	print(*out)


import sys

def solve(n, nums, s):
	z = 0
	zero_list = []
	ones_list = []
	for i in range(n):
		if s[i] == '0':
			z += 1
			zero_list.append((nums[i], i))
		else:
			ones_list.append((nums[i], i))
	if z == n or z == 0:
		return nums
	zero_list.sort(key=lambda x: x[0], reverse=True)
	ones_list.sort(key=lambda x: x[0])
	o = z + 1
	for (val, idx) in zero_list:
		nums[idx] = z
		z -= 1
	for (val, idx) in ones_list:
		nums[idx] = o
		o += 1
	return nums
t = int(input())
while t:
	n = int(input())
	nums = list(map(int, input().split()))
	s = input()
	print(*solve(n, nums, s))
	t -= 1


for i in range(int(input())):
	N = int(input())
	P = list(map(int, input().split()))
	S = input()
	G = 1
	B = 1
	L = []
	for j in range(N):
		if S[j] == '0':
			B += 1
		L.append((P[j], j))
	k = 1
	g = B
	L.sort()
	ans = [-1] * N
	for j in range(N):
		if S[L[j][1]] == '0':
			ans[L[j][1]] = k
			k += 1
		else:
			ans[L[j][1]] = g
			g += 1
	print(*ans)


cases = int(input())
for _ in range(cases):
	num = int(input())
	arr = list(map(int, input().split()))
	s = input()
	likes = [n for (n, i) in zip(arr, s) if i == '1']
	hates = [n for (n, i) in zip(arr, s) if i == '0']
	l_num = num - len(likes)
	likes.sort()
	lst1 = list(range(l_num + 1, num + 1))
	hates.sort()
	lst2 = list(range(1, l_num + 1))
	likes_map = {n: p for (n, p) in zip(likes, lst1)}
	hates_map = {n: p for (n, p) in zip(hates, lst2)}
	ans = []
	likes_map.update(hates_map)
	for n in arr:
		ans.append(likes_map[n])
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	l = sorted([(s[i], l[i], i) for i in range(n)])
	w = [0] * n
	for i in range(n):
		w[l[i][2]] = str(i + 1)
	print(' '.join(w))


def solve():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		s = input()
		ans = [-1 for _ in range(n)]
		l = []
		for i in range(n):
			l.append([s[i], arr[i], i])
		l = sorted(l)
		for i in range(n):
			ans[l[i][2]] = i + 1
		print(' '.join(list(map(str, ans))))
solve()


t = int(input())
while t:
	n = int(input())
	A = list(map(int, input().split(' ')))
	s = str(input())
	D = {}
	(B, C) = ([], [])
	for i in range(n):
		D[A[i]] = i
	for i in range(n):
		if s[i] == '1':
			B.append(A[i])
		else:
			C.append(A[i])
	B.sort()
	C.sort()
	ans = [0] * n
	m = len(B)
	if m == len(A):
		m = 1
	else:
		m = n - m + 1
	for i in range(len(B)):
		ans[D[B[i]]] = m
		m = m + 1
	m = 1
	for i in range(len(C)):
		ans[D[C[i]]] = m
		m = m + 1
	print(*ans)
	t = t - 1


t = int(input())

def sol(n, p, s):
	res = p[::1]
	sl = [int(x) for x in s]
	disliked = n - sum(sl)
	if disliked == 0:
		return res
	(b, a) = (1, disliked + 1)
	x = []
	y = []
	for (i, v) in enumerate(sl):
		if v == 1:
			x.append([i, p[i]])
		else:
			y.append([i, p[i]])
	x.sort(key=lambda num: num[1])
	y.sort(key=lambda num: num[1])
	for i in range(len(x)):
		res[x[i][0]] = a
		a += 1
	for i in range(len(y)):
		res[y[i][0]] = b
		b += 1
	return res
while t:
	t -= 1
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	res = sol(n, p, s)
	print(*res)


import sys
import io, os
import string
from io import BytesIO, IOBase
from os import path
from collections import Counter, OrderedDict
import itertools
from itertools import chain, combinations
import math
import random
import bisect
from functools import reduce
from sys import stdin, stdout
from collections import OrderedDict
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
sys.setrecursionlimit(100000000)
simp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
n = simp()

def if_its_binaryform_palindrome(n):
	res = 0
	k = n
	while k > 0:
		res = res << 1 | k & 1
		k = k >> 1
	return n == res

def solve(a, d):
	dd = [0] * len(a)
	rr = {}
	s = {}
	for j in range(len(d)):
		if d[j] == '0':
			rr[j] = a[j]
		else:
			s[j] = a[j]
	i = 0
	rrr = {k: v for (k, v) in sorted(rr.items(), key=lambda item: item[1])}
	sss = {k: v for (k, v) in sorted(s.items(), key=lambda item: item[1])}
	rr_r = {}
	ss_s = {}
	while i < len(rr):
		rr_r[i] = i + 1
		i += 1
	j = 0
	while j < len(sss):
		ss_s[i] = i + 1
		i += 1
		j += 1
	zeroes = dict(zip(rrr.keys(), rr_r.values()))
	first = dict(zip(sss.keys(), ss_s.values()))
	if len(zeroes) != 0:
		for (i, j) in zeroes.items():
			dd[i] = j
	if len(first) != 0:
		for (i, j) in first.items():
			dd[i] = j
	return dd
for i in range(n):
	d = simp()
	a = seq()
	r = strng()
	print(*solve(a, r))

def seive(n):
	prime = [1 for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == 1:
			for i in range(p ** 2, n + 1, p):
				prime[i] = 0
		p += 1
	prime[0] = 0
	prime[1] = 0
	for i in range(1, n + 1):
		prime[i] += prime[i - 1]
	return prime

def list_of_prime_sieve(n):
	primes = [True] * (n + 1)
	primes[0] == primes[1] == False
	for i in range(2, int(n ** (1 / 2)) + 1):
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
	list_primes = []
	for i in range(2, len(primes)):
		if primes[i] == True:
			list_primes.append(i)
	return list_primes

def count_primes(a):
	return len(list_of_prime_sieve(a))

def gcdoftwo(a, b):
	if a == 0:
		return b
	else:
		return gcdoftwo(b % a, a)

def lcm(a, b):
	return a * b // gcdoftwo(a, b)

def gcdofList(A):
	res = A[0]
	for c in A[1:]:
		res = gcdoftwo(res, c)
		if res == 1:
			return res
	return res

def binpow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a
		a = a * a
		b >>= 1
	return res

def fibo_in_logn(n):
	if n == 0:
		return [0, 1]
	p = fibo_in_logn(n >> 1)
	c = p.first * (2 * p.second - p.first)
	d = p.first * p.first + p.second * p.second
	if n & 1:
		return {d, c + d}
	else:
		return {c, d}

def x_n_mod_m(a, b, m):
	a = a % m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def change_array(count, t):
	emp = []
	for i in range(len(t)):
		emp.append(count[t[i]])
	return emp

def simpleSieve(limit):
	mark = [True for i in range(limit + 1)]
	p = 2
	while p * p <= limit:
		if mark[p] == True:
			for i in range(p * p, limit + 1, p):
				mark[i] = False
		p += 1
	for p in range(2, limit):
		if mark[p]:
			prime.append(p)
	return prime

def segmentedSieve(n):
	limit = int(math.floor(math.sqrt(n)) + 1)
	t = []
	t += simpleSieve(limit)
	low = limit
	high = limit * 2
	while low < n:
		if high >= n:
			high = n
		mark = [True for i in range(limit + 1)]
		for i in range(len(prime)):
			loLim = int(math.floor(low / prime[i]) * prime[i])
			if loLim < low:
				loLim += prime[i]
			for j in range(loLim, high, prime[i]):
				mark[j - low] = False
		for i in range(low, high):
			if mark[i - low]:
				t.append(i)
		low = low + limit
		high = high + limit
	return t
mod = 1000000007

def occurrences(string, sub):
	count = start = 0
	while True:
		start = string.find(sub, start) + 1
		if start > 0:
			count += 1
		else:
			return count


def solve(n, a, s):
	ar = [0] * n
	if s == ['1'] * n or s == ['0'] * n:
		a = list(map(str, a))
		return ' '.join(a)
	for i in range(n):
		ar[a[i] - 1] = i
	c = 1
	ans = [0] * n
	for i in range(n):
		if s[ar[i]] == '0':
			ans[ar[i]] = c
			c += 1
	for i in range(n):
		if s[ar[i]] == '1':
			ans[ar[i]] = c
			c += 1
	ans = list(map(str, ans))
	return ' '.join(ans)
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = list(input())
	print(solve(n, a, s))


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	s = input()
	ar_zip = sorted(zip(s, ar, range(n)))
	list1 = [0] * n
	for i in range(n):
		list1[ar_zip[i][2]] = i + 1
	print(*list1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	like = {}
	dis = {}
	for i in range(n):
		if s[i] == '1':
			like[arr[i]] = 0
		else:
			dis[arr[i]] = 0
	k = len(dis)
	k += 1
	for e in sorted(like):
		like[e] = k
		k += 1
	k = 1
	for e in sorted(dis):
		dis[e] = k
		k += 1
	for i in range(n - 1):
		if s[i] == '1':
			print(like[arr[i]], end=' ')
		else:
			print(dis[arr[i]], end=' ')
	if s[-1] == '1':
		print(like[arr[-1]])
	else:
		print(dis[arr[-1]])


for _ in range(int(input())):
	n = int(input())
	rr = list(map(int, input().split()))
	ss = input()
	kk = set(ss)
	if len(kk) == 1:
		print(*rr)
	else:
		z1 = []
		o1 = []
		ones = ss.count('1')
		zeros = n - ones
		z2 = list(range(1, zeros + 1))
		o2 = list(range(zeros + 1, n + 1))
		for i in range(n):
			if ss[i] == '1':
				o1.append(rr[i])
			else:
				z1.append(rr[i])
		o1.sort()
		z1.sort()
		onemap = {}
		zeromap = {}
		for i in range(len(o1)):
			onemap[o1[i]] = o2[i]
		for i in range(len(z1)):
			zeromap[z1[i]] = z2[i]
		ans = []
		for i in range(n):
			if ss[i] == '0':
				ans.append(zeromap[rr[i]])
			else:
				ans.append(onemap[rr[i]])
		print(*ans)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	s = input()
	d = {}
	for i in range(n):
		d[arr[i]] = i + 1
	z = []
	o = []
	for i in range(n):
		if s[i] == '0':
			z.append(i)
		else:
			o.append(i)
	z.sort(key=lambda x: arr[x])
	o.sort(key=lambda x: arr[x])
	ans = [0 for i in range(n)]
	k = 1
	for i in z:
		ans[i] = k
		k += 1
	for i in o:
		ans[i] = k
		k += 1
	if z == [] or o == []:
		print(*arr)
	else:
		print(*ans)


n = int(input())
for i in range(n):
	j = int(input())
	arr = [int(i) for i in input().split()]
	s = [int(i) for i in list(input())]
	oks = s.count(1)
	res = [0 for i in range(j)]
	ups = {}
	downs = {}
	for k in range(len(s)):
		if s[k]:
			ups[k] = arr[k]
		else:
			downs[k] = arr[k]
	ups = dict(sorted(ups.items(), key=lambda item: item[1]))
	downs = dict(sorted(downs.items(), key=lambda item: item[1]))
	o = 1
	for (k, v) in downs.items():
		res[k] = o
		o += 1
	for (k, v) in ups.items():
		res[k] = o
		o += 1
	print(' '.join([str(i) for i in res]))


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	s = str(input())
	d = {}
	for i in range(n):
		d[p[i]] = i
	selected = []
	rej = []
	for i in range(n):
		if s[i] == '1':
			selected.append(p[i])
		else:
			rej.append(p[i])
	ans = [-1 for i in range(n)]
	num = n
	selected = sorted(selected, reverse=True)
	for x in selected:
		ans[d[x]] = num
		num -= 1
	num = 1
	rej = sorted(rej)
	for x in rej:
		ans[d[x]] = num
		num += 1
	print(' '.join(map(str, ans)))


t = int(input())
while t:
	t -= 1
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	ss = set(s)
	if '1' not in ss or '0' not in ss:
		print(*p)
	else:
		ones = []
		zeroes = []
		i = 0
		while i < n:
			if s[i] == '1':
				ones.append([p[i], i])
			else:
				zeroes.append([p[i], i])
			i += 1
		ones.sort()
		zeroes.sort()
		a = [0] * n
		num = 0
		for (ele, idx) in zeroes:
			num += 1
			a[idx] = num
		for (ele, idx) in ones:
			num += 1
			a[idx] = num
		print(*a)


from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import math

def inp(force_list=False):
	re = list(map(int, input().split()))
	if len(re) == 1 and (not force_list):
		return re[0]
	return re

def inst():
	return input().strip()

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
MOD = 998244353

def query(a, b, c):
	print('! %d %d %d' % (a + 1, b + 1, c + 1))
	stdout.flush()
	return inp()

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	cost = sum(a[0:n - 2 * k]) + sum(map(lambda x: a[x + n - 2 * k] // a[x + n - k], range(0, k)))
	print(cost)

def my_main():
	kase = inp()
	pans = []
	for _ in range(kase):
		n = inp()
		da = inp(True)
		st = inst()
		(z, o) = ([], [])
		for i in range(n):
			if st[i] == '1':
				o.append((da[i], i))
			else:
				z.append((da[i], i))
		o.sort()
		z.sort()
		ans = [0] * n
		now = 1
		for i in range(len(z)):
			ans[z[i][-1]] = now
			now += 1
		for i in range(len(o)):
			ans[o[i][-1]] = now
			now += 1
		pans.append(' '.join(map(str, ans)))
	print('\n'.join(pans))
my_main()


t = int(input())
for j in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	f = []
	q = []
	d = []
	for i in range(0, n):
		q.append(0)
		d.append(0)
		f.append('0')
	for i in range(0, n):
		q[l[i] - 1] = i + 1
		if s[i] == '1':
			f[l[i] - 1] = '1'
	c = n
	for i in range(0, n):
		if f[n - i - 1] == '1':
			d[q[n - i - 1] - 1] = str(c)
			c -= 1
	for i in range(0, n):
		if f[n - i - 1] == '0':
			d[q[n - i - 1] - 1] = str(c)
			c -= 1
	print(' '.join(d))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	b = []
	c = []
	ans = [0] * n
	val = 1
	for i in range(n):
		if s[i] == '0':
			b.append([a[i], i])
			c.append(val)
			val += 1
	b.sort()
	for i in range(len(b)):
		ans[b[i][1]] = c[i]
	b = []
	c = []
	for i in range(n):
		if s[i] == '1':
			b.append([a[i], i])
			c.append(val)
			val += 1
	b.sort()
	for i in range(len(b)):
		ans[b[i][1]] = c[i]
	print(*ans)


import sys
import math
from collections import deque, Counter
from sys import stdin
int1 = lambda x: int(x) - 1
stinput = lambda : stdin.readline()[:-1]
ii = lambda : int(stinput())
mi = lambda : map(int, stdin.readline().split())
li = lambda : list(mi())
mi1 = lambda : map(int1, stdin.readline().split())
li1 = lambda : list(mi1())
mis = lambda : map(str, stdin.readline().split())
lis = lambda : list(mis())
from collections import defaultdict
import heapq
mod = 10 ** 9 + 7
Mod = 998244353
INF = 10 ** 18
ans = 0
t = ii()
for _ in range(t):
	n = ii()
	p = li1()
	s = input()
	c1 = []
	c0 = []
	for i in range(n):
		if s[i] == '0':
			c0.append((p[i], i))
		else:
			c1.append((p[i], i))
	ans = [0] * n
	c0.sort()
	c1.sort()
	tmp = 1
	for (x, y) in c0:
		ans[y] = tmp
		tmp += 1
	for (x, y) in c1:
		ans[y] = tmp
		tmp += 1
	print(*ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def lsi():
	return list(msi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def ceil2(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, factorial, cos, tan, sin, radians, floor, sqrt, ceil, log2
import bisect
import random
import string
from itertools import permutations
from decimal import *
getcontext().prec = 50
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def myKey(x):
	return (x[0], x[1])

def main():
	for _ in range(ii()):
		n = ii()
		p = li()
		s = si()
		l = []
		for i in range(n):
			l.append([int(s[i]), p[i], i])
		l.sort(key=myKey)
		ans = [0] * (n + 1)
		c = 1
		for i in range(n):
			ans[l[i][2]] = c
			c += 1
		print(*ans[0:-1])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	n1 = s.count('0')
	a1 = [0] * n
	a2 = [0] * n
	a3 = [0] * n
	a4 = [0] * n
	for i in range(n):
		if s[i] == '1':
			a1[a[i] - 1] = 1
		else:
			a1[a[i] - 1] = 0
	l = 0
	d = 0
	for i in range(n):
		if a1[i] == 1:
			l += 1
		else:
			d += 1
		a2[i] = l
		a3[i] = d
	for i in range(n):
		if s[i] == '0':
			a4[i] = a3[a[i] - 1]
		else:
			a4[i] = a2[a[i] - 1] + n1
	print(*a4)


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	q = [0] * n
	s = input()
	(liked, disliked) = ([], [])
	for i in range(n):
		song = i + 1
		if s[i] == '1':
			liked.append((p[i], i))
		else:
			disliked.append((p[i], i))
	liked.sort()
	disliked.sort()
	for i in range(len(disliked)):
		q[disliked[i][1]] = i + 1
	for i in range(len(liked)):
		q[liked[i][1]] = len(disliked) + i + 1
	print(*q)


n_testcase = int(input())
for _ in range(n_testcase):
	n = int(input())
	pre_rating = list(map(int, input().split()))
	vote = input()
	disliked_song = []
	liked_song = []
	for i in range(n):
		if vote[i] == '1':
			liked_song.append([i, pre_rating[i]])
		else:
			disliked_song.append([i, pre_rating[i]])
	liked_song.sort(key=lambda x: x[1])
	disliked_song.sort(key=lambda x: x[1])
	n_disliked_song = len(disliked_song)
	n_liked_song = len(liked_song)
	for i in range(n_disliked_song):
		pre_rating[disliked_song[i][0]] = i + 1
	for i in range(n_liked_song):
		pre_rating[liked_song[i][0]] = i + 1 + n_disliked_song
	print(' '.join(map(str, pre_rating)))


t = int(input())
for t1 in range(t):
	n = int(input())
	plist = list(map(int, input().split()))
	sbev = input()
	dislike_s = 1
	like_s = 1
	dislike_list = []
	like_list = []
	for i in range(len(sbev)):
		if sbev[i] == '0':
			like_s += 1
			dislike_list.append(plist[i])
		else:
			like_list.append(plist[i])
	dislike_list = sorted(dislike_list)
	like_list = sorted(like_list)
	dislike_index = dict()
	like_index = dict()
	answer = []
	for i in range(len(dislike_list)):
		dislike_index[dislike_list[i]] = i
	for i in range(len(like_list)):
		like_index[like_list[i]] = i
	for i in range(len(sbev)):
		if sbev[i] == '1':
			answer.append(like_index[plist[i]] + like_s)
		else:
			answer.append(dislike_index[plist[i]] + dislike_s)
	print(' '.join((str(x) for x in answer)))


N = int(200000.0)
t = int(input())
x = [0 for _ in range(N)]
x2 = [0 for _ in range(N)]
s2 = [0 for _ in range(N)]
q = [0 for _ in range(N)]
for i in range(t):
	n = int(input())
	p = [int(x) - 1 for x in input().split(' ')]
	s = input()
	for i in range(n):
		x[p[i]] = i
		s2[p[i]] = s[i]
	j = 0
	for i in range(n):
		if s2[i] == '0':
			x2[j] = x[i]
			j += 1
	for i in range(n):
		if s2[i] == '1':
			x2[j] = x[i]
			j += 1
	for i in range(n):
		q[x2[i]] = i
	print(' '.join([str(a + 1) for a in q[:n]]))


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	lst = []
	lstt = []
	for i in range(n):
		if int(s[i]) == 1:
			lstt.append([p[i], i])
		else:
			lst.append([p[i], i])
	lst.sort()
	lstt.sort()
	lsttt = []
	for j in range(1, n + 1):
		if j <= len(lst):
			lst[j - 1][0] = j
			lsttt.append([lst[j - 1][1], lst[j - 1][0]])
		else:
			lstt[j - len(lst) - 1][0] = j
			lsttt.append([lstt[j - len(lst) - 1][1], lstt[j - len(lst) - 1][0]])
	lsttt.sort()
	for i in range(n):
		lsttt[i] = lsttt[i][1]
	print(*lsttt)


def solve():
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	arr = [(char, pri, idx) for (char, pri, idx) in zip(s, p, range(n))]
	arr.sort()
	result = [0 for _ in range(n)]
	for i in range(n):
		result[arr[i][2]] = i + 1
	print(' '.join(map(str, result)))
t = int(input())
for _ in range(t):
	solve()


result = []
for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	s = list(map(int, list(input())))
	count = s.count(0)
	zeros = sorted([[p[i], i] for i in range(n) if s[i] == 0])
	ones = sorted([[p[i], i] for i in range(n) if s[i] == 1])
	answer = [None for i in range(n)]
	for (i, (value, index)) in enumerate(zeros):
		answer[index] = i + 1
	for (i, (value, index)) in enumerate(ones):
		answer[index] = count + i + 1
	result.append(answer)
print('\n'.join(map(lambda x: ' '.join(map(str, x)), result)))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input().decode('utf-8')
	arr1 = []
	arr2 = []
	for i in range(n):
		if s[i] == '1':
			arr1.append([arr[i], i])
		else:
			arr2.append([arr[i], i])
	arr1.sort()
	arr2.sort()
	method = [0] * n
	arrtot = arr2 + arr1
	for i in range(n):
		method[arrtot[i][1]] = i + 1
	print(*method)
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ans = [0] * n
	p = list(map(int, input().split()))
	p = list(enumerate(p))
	s = input()
	s0 = []
	s1 = []
	for i in range(n):
		if s[i] == '0':
			s0.append(p[i])
		else:
			s1.append(p[i])
	s0.sort(key=lambda x: x[1])
	s1.sort(key=lambda x: x[1])
	k = 1
	for i in range(len(s0)):
		ans[s0[i][0]] = k
		k += 1
	for i in range(len(s1)):
		ans[s1[i][0]] = k
		k += 1
	print(*ans)


t = int(input())
for i in range(t):
	mapper1 = {}
	mapper2 = {}
	ans = []
	n = int(input())
	rating = input().split()
	rating = [int(j) for j in rating]
	for (j, k) in enumerate(rating):
		mapper1[k] = j
	ld = list(input())
	ld = [int(j) for j in ld]
	a = 1
	b = ld.count(0) + 1
	for j in range(1, n + 1):
		if ld[mapper1[j]] == 0:
			mapper2[mapper1[j]] = a
			a += 1
		else:
			mapper2[mapper1[j]] = b
			b += 1
	for j in range(n):
		ans.append(mapper2[j])
	ans = [str(j) for j in ans]
	print(' '.join(ans))


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inps():
	return input().strip()

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	p = inlt()
	s = insr()
	l = []
	d = []
	for i in range(n):
		if s[i] == '1':
			l.append([p[i], i])
		else:
			d.append([p[i], i])
	l.sort()
	d.sort()
	vl = [len(d) + i + 1 for i in range(len(l))]
	vd = [1 + i for i in range(len(d))]
	ans = [0 for i in range(n)]
	while d:
		(a, b) = d.pop()
		idx = vd.pop()
		ans[b] = idx
	while l:
		(a, b) = l.pop()
		idx = vl.pop()
		ans[b] = idx
	print(*ans)


for _ in range(int(input())):
	x = int(input())
	per = list(map(int, input().split()))
	string = input()
	cnt1 = string.count('1')
	if cnt1 == x:
		print(*per)
		continue
	hash1 = [0] * (x + 1)
	hash2 = [0] * (x + 1)
	temp1 = x - cnt1 + 1
	temp2 = 1
	for i in range(x):
		if string[i] == '1':
			hash1[per[i]] = 1
		else:
			hash1[per[i]] = 0
	for i in range(1, x + 1):
		if hash1[i] == 0:
			hash2[i] = temp2
			temp2 += 1
		else:
			hash2[i] = temp1
			temp1 += 1
	ans = []
	for i in per:
		ans.append(hash2[i])
	print(*ans)


import sys
input = sys.stdin.readline

def read_ints():
	return list(map(int, input().strip().split()))

def read_strs():
	s = input().strip()
	return list(map(int, list(s)))

def solve(p, s):
	lower = [rating for (index, rating) in enumerate(p) if s[index] == 0]
	upper = [rating for (index, rating) in enumerate(p) if s[index] == 1]
	index_map = {}
	for (index, rating) in enumerate(p):
		index_map[rating] = index
	lower.sort()
	upper.sort()
	combined = lower + upper
	result = [0 for _ in p]
	for (index, rating) in enumerate(combined):
		result[index_map[rating]] = index + 1
	return result
n = int(input())
for i in range(n):
	m = int(input())
	p = read_ints()
	s = read_strs()
	print(*solve(p, s))


ans = []
for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	rating = [int(c) for c in input()]
	new_nums = [(rating[i], nums[i], i) for i in range(n)]
	idx_map = {nums[i]: i for i in range(n)}
	new_nums.sort()
	i = 0
	temp = [0] * n
	for (_, num, _) in new_nums:
		temp[idx_map[num]] = i + 1
		i += 1
	ans.append(temp)
for a in ans:
	print(*a)


for i in range(int(input())):
	(n, p, s) = (int(input()), [int(i) for i in input().split()], input())
	p = sorted(zip(s, p, range(n)))
	w = [0] * n
	for i in range(n):
		w[p[i][2]] = i + 1
	print(*w)
	zip()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	d = []
	e = []
	for i in range(len(s)):
		if s[i] == '0':
			d.append(a[i])
		else:
			e.append(a[i])
	d.sort()
	e.sort()
	x = {}
	y = {}
	for i in range(len(d)):
		x[d[i]] = i + 1
	for i in range(len(e)):
		y[e[i]] = len(d) + 1 + i
	for i in range(len(a)):
		if a[i] in x.keys():
			a[i] = x[a[i]]
		else:
			a[i] = y[a[i]]
	print(*a)


for _ in range(int(input())):
	n = int(input())
	p = (*map(int, input().split()),)
	s = input()
	good = []
	bad = []
	for i in range(n):
		if s[i] == '1':
			good.append(p[i])
		else:
			bad.append(p[i])
	d = {rating: index for (index, rating) in enumerate(sorted(bad), 1)}
	d.update({rating: index for (index, rating) in enumerate(sorted(good), len(bad) + 1)})
	print(' '.join((str(d[rating]) for rating in p)))


import sys
import math
from math import gcd, sqrt, log2, ceil, floor
import heapq as hq
from bisect import bisect_right, bisect_left, bisect
import itertools
from sys import stdin, stdout, setrecursionlimit

def isPowerOfTwo(x):
	return x and (not x & x - 1)
MOD = int(1000000000.0) + 7
alp = 'abcdefghijklmnopqrstuvwxyz'
v = {'a': 1, 'e': 1, 'i': 1, 'o': 1, 'u': 1}
c = {}
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	s = list(stdin.readline().strip('\n'))
	N = n
	A = [0] * n
	b = []
	for i in range(n):
		b.append([a[i], s[i], i])
	b.sort()
	for i in range(n - 1, -1, -1):
		if b[i][1] == '1':
			A[b[i][2]] = N
			N -= 1
	for i in range(n - 1, -1, -1):
		if b[i][1] == '0':
			A[b[i][2]] = N
			N -= 1
	print(*A)


t = int(input())
for q in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	s = input()
	(mx, mn, dict, c) = ([], [], {}, 1)
	for i in range(n):
		dict[arr[i]] = i
		if s[i] == '0':
			mn.append(arr[i])
		else:
			mx.append(arr[i])
	ans = [None for i in range(n)]
	mx.sort()
	mn.sort()
	for i in range(len(mn)):
		ans[dict[mn[i]]] = c
		c += 1
	for i in range(len(mx)):
		ans[dict[mx[i]]] = c
		c += 1
	print(*ans)


from collections import *
for _ in range(int(input())):
	n = int(input())
	pi = list(map(int, input().split()))
	s = str(input())
	g = []
	l = []
	gg = defaultdict(int)
	ll = defaultdict(int)
	for i in range(n):
		if s[i] == '1':
			g.append(pi[i])
		else:
			l.append(pi[i])
	g.sort()
	l.sort()
	v = 1
	for i in range(len(l)):
		ll[l[i]] = v
		v += 1
	for i in range(len(g)):
		ll[g[i]] = v
		v += 1
	ans = []
	for i in range(n):
		ans.append(ll[pi[i]])
	print(*ans)


cases = int(input())
for i in range(cases):
	n = int(input())
	entrada = input().split()
	p = []
	for j in entrada:
		p.append(int(j))
	entrada = input()
	s = [int(j) for j in entrada]
	liked_indexes = []
	disliked_indexes = []
	reverse_p = [0 for i in p]
	for i in range(n):
		reverse_p[p[i] - 1] = i
	for j in range(n, 0, -1):
		index = reverse_p[j - 1]
		if s[index] == 1:
			liked_indexes.append(index)
		else:
			disliked_indexes.append(index)
	priority = liked_indexes + disliked_indexes
	value = n
	for i in priority:
		p[i] = value
		value -= 1
	for j in range(len(p) - 1):
		print(p[j], end=' ')
	print(p[-1])


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	s = input()
	if '1' in s and '0' in s:
		c = 0
		lstl = []
		lstd = []
		for j in range(n):
			if s[j] == '1':
				c += 1
				lstl.append((lst[j], j))
			else:
				lstd.append((lst[j], j))
		lstl.sort(key=lambda y: y[0], reverse=True)
		lstd.sort(key=lambda y: y[0], reverse=True)
		f = n
		for g in lstl:
			lst[g[1]] = f
			f -= 1
		w = len(lstd)
		for d in lstd:
			lst[d[1]] = w
			w -= 1
	print(*lst)


T = int(input())

def solve():
	N = int(input())
	P = list(map(int, input().split()))
	S = input()
	like = []
	dislike = []
	for (i, c) in enumerate(S):
		if c == '0':
			dislike.append((P[i], i))
		else:
			like.append((P[i], i))
	like = sorted(like)
	dislike = sorted(dislike)
	ans = [None for _ in range(N)]
	value = 0
	for (_, idx) in dislike:
		ans[idx] = str(value + 1)
		value += 1
	for (_, idx) in like:
		ans[idx] = str(value + 1)
		value += 1
	print(' '.join(ans))
for _ in range(T):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	zero = []
	one = []
	d = {}
	for i in a:
		d[i] = 0
	for i in range(len(s)):
		if s[i] == '0':
			zero.append(a[i])
		elif s[i] == '1':
			one.append(a[i])
	zero.sort()
	one.sort()
	x = 1
	for i in zero:
		d[i] = x
		x += 1
	for i in one:
		d[i] = x
		x += 1
	print(*d.values())


for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	(z, o) = (dict(), dict())
	q = 1
	for i in range(n):
		if s[i] == '0':
			z[p[i]] = i
		else:
			o[p[i]] = i
	for i in sorted(z):
		p[z[i]] = q
		q += 1
	for i in sorted(o):
		p[o[i]] = q
		q += 1
	print(' '.join(map(str, p)))


import sys, collections
inum = lambda : int(input())
imap = lambda : map(int, input().split())
ilist = lambda : list(map(int, input().split()))
for t in range(inum()):
	(n, arr, w, ar1, ar2) = (inum(), ilist(), input(), list(), list())
	(cnt, one) = (1, 1)
	ans = [-cnt for i in range(n)]
	for i in range(0, n, 1):
		if w[i] == '0':
			ar2.append(arr[i])
		else:
			ar1.append(arr[i])
	ar1.sort()
	ar2.sort()
	mp = collections.defaultdict(lambda : 0)
	for i in ar2:
		mp[i] = cnt
		cnt += one
	for i in ar1:
		mp[i] = cnt
		cnt += one
	ans = [str(mp[arr[i]]) for i in range(n)]
	sys.stdout.write(str(' '.join(ans)) + '\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	(ps, ng) = ([], [])
	(pc, nc) = (0, 0)
	for i in range(n):
		if s[i] == '1':
			ps.append(a[i])
			pc += 1
		else:
			ng.append(a[i])
			nc += 1
	ps = sorted(ps)
	ng = sorted(ng)
	d = {}
	for i in range(len(ng)):
		d[ng[i]] = i + 1
	for i in range(len(ps)):
		d[ps[i]] = nc + i + 1
	ans = [-1 for i in range(n)]
	for i in range(n):
		ans[i] = d[a[i]]
	print(' '.join([str(i) for i in ans]))


for ___ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	s = list(map(int, list(input())))
	ratingToIdx = [i for i in range(0, n + 1)]
	ratingToLike = [i for i in range(n + 1)]
	for i in range(n):
		ratingToIdx[p[i]] = i + 1
		ratingToLike[p[i]] = s[i]
	(q1, q2) = ([], [])
	for i in range(1, n + 1):
		if ratingToLike[i] == 0:
			q1.append(ratingToIdx[i])
		else:
			q2.append(ratingToIdx[i])
	newIdx = [-1] + q1 + q2
	for i in range(n):
		p[newIdx[i + 1] - 1] = i + 1
	print(' '.join(map(str, p)))


def find(n, p, s):
	low = []
	high = []
	for i in range(n):
		if int(s[i]) == 0:
			low.append(p[i])
		else:
			high.append(p[i])
	a = len(low)
	b = len(high)
	low.sort()
	high.sort()
	map = {}
	for i in range(a):
		map[low[i]] = i + 1
	for i in range(b):
		map[high[i]] = i + a + 1
	q = []
	for i in range(n):
		q.append(str(map[p[i]]))
	return ' '.join(q)
cases = int(input())
for _ in range(cases):
	n = int(input())
	line = input().split()
	s = input()
	p = []
	for elem in line:
		p.append(int(elem))
	print(find(n, p, s))


def pl(line, func):
	return [func(i) for i in line.split()]
ip = input
n = int(ip())
for i in range(n):
	song_cnt = int(ip())
	songs = pl(ip(), int)
	res = ip()
	order = sorted(range(song_cnt), key=lambda x: songs[x] + (res[x] == '1') * 2000000.0)
	songs.sort()
	ans = [-1] * song_cnt
	for (song_id, val) in zip(order, songs):
		ans[song_id] = val
	print(' '.join((str(i) for i in ans)))


z = int(input())
for i in range(z):
	q = []
	g = int(input())
	g1 = [int(i) for i in input().split()]
	h = input()
	l = len(h)
	r = [0] * l
	for k in range(l):
		a = (h[k], g1[k], k)
		q.append(a)
	q = sorted(q, key=lambda p: (p[0], p[1]))
	for (o, u) in enumerate(q):
		r[u[2]] = str(o + 1)
	if 1 + 1 == 2:
		r1 = r
		r2 = r1
		print(' '.join(r2))


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	n = I()
	p = L()
	s = S()
	a = []
	b = []
	ans = [0] * n
	for i in range(n):
		if s[i] == '1':
			a.append((p[i], i))
		else:
			b.append((p[i], i))
	a.sort(key=lambda x: x[0])
	b.sort(key=lambda x: x[0])
	k = len(a)
	j = len(b)
	t = 0
	for i in range(n - k + 1, n + 1):
		ans[a[t][1]] = i
		t += 1
	for i in range(j):
		ans[b[i][1]] = i + 1
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	s = input()
	l = []
	for i in range(len(s)):
		l.append([arr[i], int(s[i]), i])
	l.sort()
	dic = {0: [], 1: []}
	for i in l:
		dic[i[1]].append(i[2])
	res = [0 for i in range(len(s))]
	c = 1
	for i in dic[0]:
		res[i] = c
		c += 1
	for i in dic[1]:
		res[i] = c
		c += 1
	print(*res)


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	b = sorted(zip(s, arr, range(n)))
	ans = [0] * n
	for i in range(n):
		ans[b[i][2]] = i + 1
	return ans
import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
	print(*solve())


for i in range(int(input())):
	n = int(input())
	pi = list(map(int, input().split()))
	si = input()
	dic = {}
	for i in pi:
		dic[i] = 0
	dislike = []
	like = []
	for i in range(n):
		if si[i] == '0':
			dislike.append(pi[i])
		else:
			like.append(pi[i])
	all = sorted(dislike) + sorted(like)
	q = 1
	while q <= n:
		dic[all[q - 1]] = q
		q += 1
	print(*dic.values())


import math
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = input().strip()
	id = [0] * (n + 1)
	for i in range(n):
		id[a[i]] = i + 1
	l = []
	d = []
	for i in range(n):
		if s[i] != '0':
			l.append(a[i])
		else:
			d.append(a[i])
	l.sort()
	d.sort()
	res = [0] * (n + 1)
	c = 1
	for i in d:
		res[id[i]] = c
		c += 1
	for i in l:
		res[id[i]] = c
		c += 1
	res.pop(0)
	print(*res)


import sys
input = sys.stdin.readline
num_test_cases = int(input())
for test_case_ittr in range(num_test_cases):
	n = int(input())
	rankings = [int(x) for x in input().split()]
	feedback = [int(x) for x in input().strip()]
	goods = []
	bads = []
	for (rank, fb, i) in zip(rankings, feedback, range(n)):
		if fb:
			goods += [(rank, i)]
		else:
			bads += [(rank, i)]
	arr = sorted(bads) + sorted(goods)
	ans = [None for _ in range(n)]
	for (i, (_, old_i)) in enumerate(arr):
		ans[old_i] = i + 1
	print(*ans)


import sys
for i in range(int(input())):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split()))
	s = list(sys.stdin.readline())
	del s[-1]
	x = 0
	c = 0
	c1 = 0
	e = []
	f = []
	for j in range(n):
		if s[j] == '0':
			e.append((a[j], j))
			x += 1
		else:
			f.append((a[j], j))
	e.sort()
	f.sort()
	y = n - x
	for j in range(x):
		s[e[j][1]] = j + 1
	for j in range(y):
		s[f[j][1]] = x + 1 + j
	print(' '.join([str(i) for i in s]))


t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	d = {}
	s = input()
	d['0'] = []
	d['1'] = []
	for i in range(n):
		d[s[i]].append(li[i])
	e = d.copy()
	e['0'].sort()
	e['1'].sort()
	ans = [0] * n
	c = 1
	for i in e['0']:
		ans[i - 1] = c
		c += 1
	for i in e['1']:
		ans[i - 1] = c
		c += 1
	kemp = []
	for i in li:
		kemp.append(ans[i - 1])
	print(*kemp)


t = int(input())
for _ in range(t):
	n = int(input())
	p = [int(i) for i in input().split()]
	s = str(input())
	temp = []
	disliked = []
	liked = []
	q = [0] * n
	for i in range(len(s)):
		if s[i] == '1':
			liked.append([p[i], i])
		else:
			disliked.append([p[i], i])
	liked.sort()
	disliked.sort()
	x = 1
	for element in disliked + liked:
		q[element[1]] = x
		x += 1
	print(*q)


import sys

def berland_music(n, p, s):
	ones = []
	zeros = []
	for i in range(n):
		if s[i] == '1':
			ones += [i]
		else:
			zeros += [i]
	zero_weights = list(range(1, len(zeros) + 1))
	one_weights = list(range(len(zeros) + 1, n + 1))
	ones.sort(key=lambda x: -p[x])
	zeros.sort(key=lambda x: -p[x])
	output = [None] * n
	for z in zeros:
		output[z] = zero_weights.pop()
	for o in ones:
		output[o] = one_weights.pop()
	return ' '.join(map(str, output))
for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	sys.stdout.write(f'{berland_music(n, p, s)}\n')


from collections import defaultdict
inum = lambda : int(input())
imap = lambda : map(int, input().split())
ilist = lambda : list(map(int, input().split()))
for t in range(inum()):
	n = inum()
	arr = ilist()
	w = input()
	res = [-1 for i in range(n)]
	(cnt, one, zero) = (1, [], [])
	for i in range(n):
		if w[i] == '1':
			one.append(arr[i])
		else:
			zero.append(arr[i])
	(one, zero) = (sorted(one), sorted(zero))
	hp = defaultdict(int)
	for i in zero:
		hp[i] = cnt
		cnt += 1
	for i in one:
		hp[i] = cnt
		cnt += 1
	for i in range(n):
		res[i] = hp[arr[i]]
	print(*res)


for case in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	L2 = list(map(int, input()))
	likes = N - sum(L2) + 1
	cur = 1
	index = {L[x]: x for x in range(N)}
	ans = [0] * N
	for x in range(1, N + 1):
		i = index[x]
		if L2[i] == 0:
			ans[i] = cur
			cur += 1
		else:
			ans[i] = likes
			likes += 1
	print(' '.join(map(str, ans)))


def semiSort(arr1, arr2):
	sortedArr1 = sorted(arr1)
	sortedArr2 = sorted(arr2)
	newArr2 = [-1] * len(arr2)
	indexArr1 = {}
	for i in range(len(arr1)):
		indexArr1[arr1[i]] = i
	d = {}
	for i in range(len(arr1)):
		d[i] = indexArr1[sortedArr1[i]]
		newArr2[d[i]] = sortedArr2[i]
	return newArr2
t = int(input())
for i in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	sortedP = sorted(p)
	liked = []
	disliked = []
	p1 = []
	p2 = []
	for i in range(n):
		if s[i] == '1':
			liked.append(i)
			p1.append(p[i])
		else:
			disliked.append(i)
			p2.append(p[i])
	ptmp = sortedP[n - len(liked):n]
	ptmp2 = sortedP[0:len(disliked)]
	ans = [-1] * n
	p1 = semiSort(p1, ptmp)
	p2 = semiSort(p2, ptmp2)
	for i in range(len(liked)):
		ans[liked[i]] = p1[i]
	for i in range(len(disliked)):
		ans[disliked[i]] = p2[i]
	print(*ans)


from sys import stdin
n = int(stdin.readline().strip())
for i in range(n):
	sn = int(stdin.readline().strip())
	pp = [int(x) for x in stdin.readline().split()]
	likes = [bool(int(x)) for x in stdin.readline().strip()]
	liked_pp = [pp[i] for i in range(sn) if likes[i]]
	disliked_pp = [pp[i] for i in range(sn) if not likes[i]]
	liked_ppd = {p: i for (i, p) in enumerate(sorted(liked_pp))}
	liked_qq = {p: liked_ppd[p] + len(disliked_pp) + 1 for p in liked_pp}
	disliked_ppd = {p: i for (i, p) in enumerate(sorted(disliked_pp))}
	disliked_qq = {p: disliked_ppd[p] + 1 for p in disliked_pp}
	qq = [liked_qq[p] if p in liked_qq else disliked_qq[p] for p in pp]
	print(' '.join([str(q) for q in qq]))


import sys
get = sys.stdin.readline
for _ in range(int(get())):
	N = int(get())
	p = list(map(int, get().split()))
	s = str(get())
	likes = s.count('1')
	dislikes = s.count('0')
	disliked_songs = [0] * dislikes
	j = 0
	for i in range(N):
		if s[i] == '0':
			disliked_songs[j] = p[i]
			j += 1
	disliked_songs.sort()
	rating = [x for x in p]
	rat = 1
	liked_songs = [0] * likes
	j = 0
	for i in range(N):
		if s[i] == '1':
			liked_songs[j] = p[i]
			j += 1
	liked_songs.sort()
	chup = {}
	for x in disliked_songs:
		chup[x] = rat
		rat += 1
	for x in liked_songs:
		chup[x] = rat
		rat += 1
	for i in range(N):
		rating[i] = chup[p[i]]
	print(*rating)


def solve(n, p, s):
	idx = list(range(n))
	idx.sort(key=lambda i: (s[i], p[i]))
	ans = [0] * n
	for i in range(n):
		ans[idx[i]] = i + 1
	return ans
tests = int(input())
for test in range(tests):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	print(*solve(n, p, s))


def func():
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	reql = [0 for i in range(n)]
	d1 = {}
	d2 = {}
	for i in range(n):
		if s[i] == '1':
			d1[l[i]] = i
		elif s[i] == '0':
			d2[l[i]] = i
	k1 = len(d1)
	res1 = {key: d1[key] for key in sorted(d1)}
	res2 = {key: d2[key] for key in sorted(d2)}
	sidx1 = n - k1 + 1
	sidx2 = 1
	for i in res1:
		reql[res1[i]] = str(sidx1)
		sidx1 += 1
	for i in res2:
		reql[res2[i]] = str(sidx2)
		sidx2 += 1
	return ' '.join(reql)
t = int(input())
for i in range(t):
	print(func())


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	like = []
	dislike = []
	ind = []
	d = dict()
	if s.count('0') == 0:
		print(*p)
	elif s.count('1') == 0:
		print(*p)
	else:
		like = []
		dislike = []
		for i in range(n):
			if s[i] == '1':
				like.append(p[i])
			else:
				dislike.append(p[i])
		like.sort()
		dislike.sort()
		x = dislike + like
		for j in range(len(x)):
			d[x[j]] = j + 1
		for k in range(len(p)):
			p[k] = d[p[k]]
		print(*p)


from sys import stdin, stdout
rd = lambda : list(map(int, stdin.readline().split()))
rds = lambda : stdin.readline().rstrip()
ii = lambda : int(stdin.readline())
INF = 1 << 62
mod = 10 ** 9 + 7
for _ in range(ii()):
	n = ii()
	ps = rd()
	rs = rds()
	z = []
	o = []
	for (p, r) in zip(ps, rs):
		if r == '0':
			z.append(p)
		else:
			o.append(p)
	z.sort()
	o.sort()
	m = {}
	for (i, x) in enumerate(z):
		m[x] = i + 1
	for (j, y) in enumerate(o):
		m[y] = j + 1 + len(z)
	ans = []
	for x in ps:
		ans.append(m[x])
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	l1 = []
	l2 = []
	for i in range(n):
		if s[i] == '1':
			l2.append(l[i])
		else:
			l1.append(l[i])
	l1.sort()
	l2.sort()
	l1 = l1 + l2
	d = {}
	for i in range(n):
		d[l1[i]] = i + 1
	y = []
	for i in range(n):
		y.append(d[l[i]])
	print(*y)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
import math
import heapq
import bisect
import collections

def ceil(a, b):
	return (a + b - 1) // b
BUFSIZE = 8192
inf = float('inf')

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
get = lambda : sys.stdin.readline().rstrip('\r\n')
MOD = 1000000007

def v():
	return list()
for _ in range(int(get())):
	n = int(get())
	l = list(map(int, get().split()))
	s = get()
	l1 = []
	l2 = []
	for i in range(n):
		if s[i] == '0':
			l1.append([i, l[i]])
		else:
			l2.append([i, l[i]])
	l2.sort(key=lambda x: x[1])
	l1.sort(key=lambda x: x[1])
	l3 = l1 + l2
	l.sort()
	ans = [0] * n
	for i in range(n):
		if s[i] == '0':
			ans[l3[i][0]] = l[i]
		else:
			ans[l3[i][0]] = l[i]
	print(*ans)


T = int(input())
for testcase in range(1, T + 1):
	n = int(input())
	p = list(map(int, input().split()))
	s = list(input())
	q = [0 for i in range(n)]
	newvalue = [int(s[k]) * (n + 1) + p[k] for k in range(n)]
	enum = list(enumerate(newvalue))
	mylist = sorted(enum, key=lambda x: x[1])
	for (i, value) in enumerate(mylist):
		q[value[0]] = i + 1
	print(*q)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, functools, copy, random
from functools import reduce
import operator
inf = 10 ** 9 + 7
mod = 10 ** 9 + 7

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def LS():
	return input().split()

def endl():
	return print('\n')

def lcm(a, b):
	return a * b // math.gcd(a, b)

def grayCode(n):
	return n ^ n >> 1
sys.setrecursionlimit(20000)
graph = collections.defaultdict(list)
grid = []
visited = set()
ways = ['D', 'U', 'R', 'L']
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

def find(i):
	if par[i] != i:
		par[i] = find(par[i])
	return par[i]

def union(a, b):
	a = find(a)
	b = find(b)
	if a == b:
		return False
	par[a] = b
	return True

def initGraph(m):
	for _ in range(m):
		(u, v) = LI()
		graph[u - 1].append(v - 1)
		graph[v - 1].append(u - 1)
	return graph

def initGraphW(m):
	for _ in range(m):
		(a, b, c) = LI()
		graph[a - 1].append((b - 1, c))
		graph[b - 1].append((a - 1, c))

def initGrid(h, w):
	for i in range(h):
		s = S()
		grid.append(list(s))
	return grid

def soe(limit):
	a = [True] * limit
	a[0] = a[1] = False
	for (i, isprime) in enumerate(a):
		if isprime:
			yield i
			for n in range(i * i, limit, i):
				a[n] = False
	return a
for _ in range(I()):
	n = I()
	a = LI()
	b = S()
	b = [int(i) for i in b]
	newA = []
	for i in range(n):
		newA.append((a[i], b[i], i))
	newA.sort()
	ans = [0] * n
	i = 0
	cur = 1
	while i < n:
		if newA[i][1] == 0:
			ans[newA[i][2]] = cur
			cur += 1
		i += 1
	i = 0
	while i < n:
		if newA[i][1] == 1:
			ans[newA[i][2]] = cur
			cur += 1
		i += 1
	print(*ans)


from sys import stdin, stdout, setrecursionlimit
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	p = list(map(int, stdin.readline().rstrip().split()))
	s = stdin.readline().strip('\n')
	tmp = [int(i) for i in s]
	s = tmp
	d = {}
	l = {}
	arr_d = []
	arr_l = []
	for i in range(n):
		if s[i] == 1:
			d[p[i]] = i
			arr_d.append((p[i], i))
		else:
			l[p[i]] = i
			arr_l.append((p[i], i))
	ln = len(l)
	arr_d.sort()
	arr_l.sort()
	ans = [-1] * n
	c = 1
	for i in arr_l:
		ans[i[1]] = c
		c += 1
	for i in arr_d:
		ans[i[1]] = c
		c += 1
	print(*ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	a = 0
	b = n - 1
	l = inlt()
	s = list(map(int, insr()))
	index = [i for i in range(n)]
	zp = list(zip(s, l, index))
	zp.sort()
	ans = [0 for i in range(n)]
	l.sort()
	zero = s.count(0)
	cnt = 1
	for i in range(n):
		if zero:
			ans[zp[i][2]] = cnt
			cnt += 1
			zero -= 1
		else:
			ans[zp[i][2]] = cnt
			cnt += 1
	print(*ans)


import sys

def solve():
	inp = sys.stdin.readline
	n = int(inp())
	p = list(map(int, inp().split()))
	pi = [None] * (n + 1)
	for i in range(n):
		pi[p[i]] = i
	s = inp()
	ans = [None] * n
	c = [0, 0]
	for i in range(1, n + 1):
		x = pi[i]
		y = int(s[x])
		ans[x] = c[y]
		c[y] += 1
	o = [1, 1 + c[0]]
	for i in range(1, n + 1):
		x = pi[i]
		y = int(s[x])
		ans[x] += o[y]
	print(' '.join(map(str, ans)))

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


def do(p_arr, s_arr):
	l = len(s_arr)
	q_arr = [0] * l
	ones_arr = [p_arr[i] for i in range(l) if s_arr[i] == 1]
	ones_index = [i for i in range(l) if s_arr[i] == 1]
	ones_total = [[ones_arr[i], ones_index[i]] for i in range(len(ones_arr))]
	ones_total.sort()
	ones_index = [i[1] for i in ones_total]
	zeros_arr = [p_arr[i] for i in range(l) if s_arr[i] == 0]
	zeros_index = [i for i in range(l) if s_arr[i] == 0]
	zeros_total = [[zeros_arr[i], zeros_index[i]] for i in range(len(zeros_arr))]
	zeros_total.sort()
	zeros_index = [i[1] for i in zeros_total]
	bigg = list(range(l - len(ones_arr) + 1, l + 1))
	small = list(range(1, l - len(ones_arr) + 1))
	for j in range(len(ones_arr)):
		q_arr[ones_index[j]] = bigg[j]
	for j in range(len(zeros_arr)):
		q_arr[zeros_index[j]] = small[j]
	print(*q_arr)
t = int(input())
for i in range(t):
	n = int(input())
	p_arr = list(map(int, input().split()))
	s_arr = input()
	s_arr = [int(a) for a in s_arr]
	do(p_arr, s_arr)


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	s = input()
	bad = []
	good = []
	for i in range(len(s)):
		if s[i] == '0':
			bad.append(p[i])
		else:
			good.append(p[i])
	bad = list(sorted(bad))
	good = list(sorted(good))
	dic = {}
	start = 1
	for i in bad + good:
		dic[i] = start
		start += 1
	ans = []
	for i in p:
		ans.append(str(dic[i]))
	print(' '.join(ans))


t = int(input())
for i in range(t):
	n = int(input())
	inra = list(map(int, input().split()))
	pos = [0 for i in range(n + 1)]
	nera = [0 for i in range(n)]
	bm = input()
	o = []
	z = []
	for j in range(n):
		pos[inra[j]] = j
		if bm[j] == '0':
			z.append(inra[j])
		else:
			o.append(inra[j])
	z.sort()
	o.sort()
	x = 1
	for j in z:
		nera[pos[j]] = x
		x += 1
	for j in o:
		nera[pos[j]] = x
		x += 1
	print(*nera)


from sys import stdin, stdout, setrecursionlimit
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify, heappush, heappop, heappushpop
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sumx = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	a = L()
	s = [int(i) for i in S()]
	d = []
	e = []
	ind = [0] * (n + 1)
	for i in range(n):
		ind[a[i]] = i
	for i in range(n):
		if not s[i]:
			d += (a[i],)
		else:
			e += (a[i],)
	d.sort(reverse=True)
	e.sort()
	for i in range(s.count(0)):
		a[ind[d[-1]]] = i + 1
		d.pop()
	for i in range(s.count(1)):
		a[ind[e[-1]]] = n - i
		e.pop()
	print(*a)