#P1704A. Two 0-1 Sequences
Two 0-1 Sequences
Description
AquaMoon has two binary sequences $a$ and $b$, which contain only $0$ and $1$. AquaMoon can perform the following two operations any number of times ($a_1$ is the first element of $a$, $a_2$ is the second element of $a$, and so on):
- Operation 1: if $a$ contains at least two elements, change $a_2$ to $\operatorname{min}(a_1,a_2)$, and remove the first element of $a$.
- Operation 2: if $a$ contains at least two elements, change $a_2$ to $\operatorname{max}(a_1,a_2)$, and remove the first element of $a$.
Note that after a removal of the first element of $a$, the former $a_2$ becomes the first element of $a$, the former $a_3$ becomes the second element of $a$ and so on, and the length of $a$ reduces by one.
Determine if AquaMoon can make $a$ equal to $b$ by using these operations.
The first line contains a single integer $t$ ($1 \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 $n$, $m$ ($1 \leq n,m \leq 50$, $m \leq n$) — the lengths of $a$ and $b$ respectively.
The second line of each test case contains a string $a$ of length $n$, consisting only $0$ and $1$.
The third line of each test case contains a string $b$ of length $m$, consisting only $0$ and $1$.
For each test case, output "YES" if AquaMoon can change $a$ to $b$ 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).
Input
The first line contains a single integer $t$ ($1 \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 $n$, $m$ ($1 \leq n,m \leq 50$, $m \leq n$) — the lengths of $a$ and $b$ respectively.
The second line of each test case contains a string $a$ of length $n$, consisting only $0$ and $1$.
The third line of each test case contains a string $b$ of length $m$, consisting only $0$ and $1$.
Output
For each test case, output "YES" if AquaMoon can change $a$ to $b$ 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).
Samples
<div class="test-example-line test-example-line-even test-example-line-0">10</div><div class="test-example-line test-example-line-odd test-example-line-1">6 2</div><div class="test-example-line test-example-line-odd test-example-line-1">001001</div><div class="test-example-line test-example-line-odd test-example-line-1">11</div><div class="test-example-line test-example-line-even test-example-line-2">6 2</div><div class="test-example-line test-example-line-even test-example-line-2">110111</div><div class="test-example-line test-example-line-even test-example-line-2">01</div><div class="test-example-line test-example-line-odd test-example-line-3">6 2</div><div class="test-example-line test-example-line-odd test-example-line-3">000001</div><div class="test-example-line test-example-line-odd test-example-line-3">11</div><div class="test-example-line test-example-line-even test-example-line-4">6 2</div><div class="test-example-line test-example-line-even test-example-line-4">111111</div><div class="test-example-line test-example-line-even test-example-line-4">01</div><div class="test-example-line test-example-line-odd test-example-line-5">8 5</div><div class="test-example-line test-example-line-odd test-example-line-5">10000101</div><div class="test-example-line test-example-line-odd test-example-line-5">11010</div><div class="test-example-line test-example-line-even test-example-line-6">7 4</div><div class="test-example-line test-example-line-even test-example-line-6">1010001</div><div class="test-example-line test-example-line-even test-example-line-6">1001</div><div class="test-example-line test-example-line-odd test-example-line-7">8 6</div><div class="test-example-line test-example-line-odd test-example-line-7">01010010</div><div class="test-example-line test-example-line-odd test-example-line-7">010010</div><div class="test-example-line test-example-line-even test-example-line-8">8 4</div><div class="test-example-line test-example-line-even test-example-line-8">01010101</div><div class="test-example-line test-example-line-even test-example-line-8">1001</div><div class="test-example-line test-example-line-odd test-example-line-9">8 4</div><div class="test-example-line test-example-line-odd test-example-line-9">10101010</div><div class="test-example-line test-example-line-odd test-example-line-9">0110</div><div class="test-example-line test-example-line-even test-example-line-10">7 5</div><div class="test-example-line test-example-line-even test-example-line-10">1011100</div><div class="test-example-line test-example-line-even test-example-line-10">11100</div><div class="test-example-line test-example-line-even test-example-line-10"></div>
YES
YES
NO
NO
NO
YES
YES
NO
NO
YES
Note
In the first test case, you can use Operation 2 four times to make $a$ equals to $b$.
In the second test case, you can use Operation 1 four times to make $a$ equals to $b$.
In the third test case, it can be proved that no matter how we use the operations, it is impossible to make $a$ equal to $b$.
In the fourth test case, it can be proved that no matter how we use the operations, it is impossible to make $a$ equal to $b$.
In the fifth test case, you can use Operation 2 three times to make $a$ become $10101$, so the first element of $a$ equals to the first element of $b$, but it can be proved that no matter how to operate, the second to the fifth elements of $a$ can't be the same as $b$.