t = int(input())
for _ in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
s = input()
d = {}
flag = True
for i in range(n):
if arr[i] not in d:
d[arr[i]] = s[i]
else:
if d[arr[i]] == s[i]:
continue
else:
flag = False
break
if flag:
print('YES')
else:
print('NO')
#include<bits/stdc++.h>
using namespace std;
#define cisws cin.tie (0); ios::sync_with_stdio (false); cout.tie(0);
#define ll long long
const int N = 1e5 + 7, mod = 1e9 + 7;
int n, t, m;
ll a[N], b[N];
void solve()
{
char c[80];
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[i];
}
for(int i = 1; i <= n; i ++){
cin >> c[i];
}
for(int i = 1; i <= n; i ++){
for(int j = i + 1; j <= n; j ++){
if(a[i] == a[j] && c[i] != c[j]){
cout << "NO" << '\n';
return ;
}
}
}
cout << "YES" << '\n';
}
int main()
{
cisws
cin >> t;
while(t--)
{
solve();
}
}
1735B - Tea with Tangerines | 1735C - Phase Shift |
1321C - Remove Adjacent | 281B - Nearest Fraction |
1043A - Elections | 1598C - Delete Two Elements |
1400C - Binary String Reconstruction | 1734D - Slime Escape |
1499A - Domino on Windowsill | 991A - If at first you don't succeed |
1196C - Robot Breakout | 373A - Collecting Beats is Fun |
965A - Paper Airplanes | 863E - Turn Off The TV |
630E - A rectangle | 1104A - Splitting into digits |
19C - Deletion of Repeats | 1550B - Maximum Cost Deletion |
1693A - Directional Increase | 735D - Taxes |
989A - A Blend of Springtime | 339C - Xenia and Weights |
608A - Saitama Destroys Hotel | 1342C - Yet Another Counting Problem |
548A - Mike and Fax | 109A - Lucky Sum of Digits |
864C - Bus | 626B - Cards |
1221A - 2048 Game | 1374D - Zero Remainder Array |