CF2029B.Replacement

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

Replacement

You have a binary string^{\text{∗}} ss of length nn, and Iris gives you another binary string rr of length n1n-1.

Iris is going to play a game with you. During the game, you will perform n1n-1 operations on ss. In the ii-th operation (1in11 \le i \le n-1):

  • First, you choose an index kk such that 1ks11\le k\le |s| - 1 and sksk+1s_{k} \neq s_{k+1}. If it is impossible to choose such an index, you lose;
  • Then, you replace sksk+1s_ks_{k+1} with rir_i. Note that this decreases the length of ss by 11.

If all the n1n-1 operations are performed successfully, you win.

Determine whether it is possible for you to win this game.

^{\text{∗}}A binary string is a string where each character is either 0 or 1.

Input

Each test contains multiple test cases. The first line of the input contains a single integer tt (1t1041\le t\le 10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (2n1052\le n\le 10^5) — the length of ss.

The second line contains the binary string ss of length nn (si=0s_i=\mathtt{0} or 1).

The third line contains the binary string rr of length n1n-1 (ri=0r_i=\mathtt{0} or 1).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, print "YES" (without quotes) if you can win the game, and "NO" (without quotes) otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first test case, you cannot perform the first operation. Thus, you lose the game.

In the second test case, you can choose k=1k=1 in the only operation, and after that, ss becomes equal to 1. Thus, you win the game.

In the third test case, you can perform the following operations: 1}\underline{\mathtt{10}}\mathtt{1}\xrightarrow{r_1=\mathtt{0}} \mathtt{1}\underline{\mathtt{01}} \xrightarrow{r_2=\mathtt{0}} \underline{\mathtt{10}} \xrightarrow{r_3=\mathtt{1}} \mathtt{1.

Samples

6
2
11
0
2
01
1
4
1101
001
6
111110
10000
6
010010
11010
8
10010010
0010010
NO
YES
YES
NO
YES
NO

在线编程 IDE

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