CF1704A.Two 0-1 Sequences

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

Two 0-1 Sequences

AquaMoon has two binary sequences aa and bb, which contain only 00 and 11. AquaMoon can perform the following two operations any number of times (a1a_1 is the first element of aa, a2a_2 is the second element of aa, and so on):

  • Operation 1: if aa contains at least two elements, change a2a_2 to min(a1,a2)\operatorname{min}(a_1,a_2), and remove the first element of aa.
  • Operation 2: if aa contains at least two elements, change a2a_2 to max(a1,a2)\operatorname{max}(a_1,a_2), and remove the first element of aa.

Note that after a removal of the first element of aa, the former a2a_2 becomes the first element of aa, the former a3a_3 becomes the second element of aa and so on, and the length of aa reduces by one.

Determine if AquaMoon can make aa equal to bb by using these operations.

Input

The first line contains a single integer tt (1t20001 \leq t \leq 2\,000) — the number of test cases. Description of test cases follows.

The first line of each test case contains two integers nn, mm (1n,m501 \leq n,m \leq 50, mnm \leq n) — the lengths of aa and bb respectively.

The second line of each test case contains a string aa of length nn, consisting only 00 and 11.

The third line of each test case contains a string bb of length mm, consisting only 00 and 11.

Output

For each test case, output "YES" if AquaMoon can change aa to bb by using these options; otherwise, output "NO".

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

Note

In the first test case, you can use Operation 2 four times to make aa equals to bb.

In the second test case, you can use Operation 1 four times to make aa equals to bb.

In the third test case, it can be proved that no matter how we use the operations, it is impossible to make aa equal to bb.

In the fourth test case, it can be proved that no matter how we use the operations, it is impossible to make aa equal to bb.

In the fifth test case, you can use Operation 2 three times to make aa become 1010110101, so the first element of aa equals to the first element of bb, but it can be proved that no matter how to operate, the second to the fifth elements of aa can't be the same as bb.

Samples

10
6 2
001001
11
6 2
110111
01
6 2
000001
11
6 2
111111
01
8 5
10000101
11010
7 4
1010001
1001
8 6
01010010
010010
8 4
01010101
1001
8 4
10101010
0110
7 5
1011100
11100
YES
YES
NO
NO
NO
YES
YES
NO
NO
YES

在线编程 IDE

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