A. Number Replacement

原题

An integer array a1,a2,…,ana1,a2,…,an is being transformed into an array of lowercase English letters using the following prodecure:

While there is at least one number in the array:

  • Choose any number xx from the array aa, and any letter of the English alphabet yy.
  • Replace all occurrences of number xx with the letter yy.

For example, if we initially had an array a=[2,3,2,4,1]a=[2,3,2,4,1], then we could transform it the following way:

  • Choose the number 22 and the letter c. After that a=[c,3,c,4,1]a=[c,3,c,4,1].
  • Choose the number 33 and the letter a. After that a=[c,a,c,4,1]a=[c,a,c,4,1].
  • Choose the number 44 and the letter t. After that a=[c,a,c,t,1]a=[c,a,c,t,1].
  • Choose the number 11 and the letter a. After that a=[c,a,c,t,a]a=[c,a,c,t,a].

After the transformation all letters are united into a string, in our example we get the string "cacta".

Having the array aa and the string ss determine if the string ss could be got from the array aa after the described transformation?

Input

The first line contains a single integer tt (1≤t≤103(1≤t≤103) — the number of test cases.

Then the description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤501≤n≤50) — the length of the array aa and the string ss.

The second line of each test case contains exactly nn integers: a1,a2,…,ana1,a2,…,an (1≤ai≤501≤ai≤50) — the elements of the array aa.

The third line of each test case contains a string ss of length nn, consisting of lowercase English letters.

Output

For each test case, output "YES", if we can get the string ss from the array aa, and "NO" otherwise. You can output each letter in any case.

Example

input

Copy


7

5

2 3 2 4 1

cacta

1

50

a

2

11 22

ab

4

1 2 2 1

aaab

5

1 2 3 2 1

aaaaa

6

1 10 2 9 3 8

azzfdb

7

1 2 3 4 1 1 2

abababb

output

Copy

YES
YES
YES
NO
YES
YES
NO

Note

The first test case corresponds to the sample described in the statement.

In the second test case we can choose the number 5050 and the letter a.

In the third test case we can choose the number 1111 and the letter a, after that a=[a,22]a=[a,22]. Then we choose the number 2222 and the letter b and get a=[a,b]a=[a,b].

In the fifth test case we can change all numbers one by one to the letter a.

 

一个整数数组a1,a2,...,an正被转换成小写英文字母数组,使用以下程序。

当数组中至少有一个数字时。

从数组a中选择任何数字x,以及任何英文字母y。
用字母y替换所有出现的数字x。
例如,如果我们最初有一个数组a=[2,3,2,4,1],那么我们可以按以下方式进行转换。

选择数字2和字母c,之后a=[c,3,c,4,1]。
选择数字3和字母a,之后a=[c,a,c,4,1]。
选择数字4和字母t,然后a=[c,a,c,t,1]。
选择数字1和字母a,然后a=[c,a,c,t,a]。
在转换之后,所有的字母都被合并成一个字符串,在我们的例子中,我们得到了字符串 "cacta"。

有一个数组a和一个字符串s,请问经过上述转换后,是否可以从数组a中得到字符串s?

 思维题,只要注意匹配,未匹配的进行匹配,已经匹配过的检查是否匹配

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define dbug cout<<"hear!"<> t;
	while (t--)
	{
		cin >> n;
		for (int i = 0;i < n;i++)
		{
			cin >> a[i];
		}
		string s;
		cin >> s;
		mapmp;
		for (int i = 1;i <= 50;i++)
		{
			mp[i] = '.';
		}
		int cnt = 0;
		for (int i = 0;i < n;i++)
		{
			if (mp[a[i]] == '.')
			{
				mp[a[i]] = s[i];
				cnt++;
			}
			else if(mp[a[i]]==s[i])
			{
				cnt++;
			}
		}
		//cout << cnt << endl;
		if (cnt == n)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

 

你可能感兴趣的:(c++,算法,学习)