#P15498. [ICPC 2025 APC] Corrupted File

[ICPC 2025 APC] Corrupted File

Description

The WannaLaugh malware is a new computer malware that is spreading on the internet. If a computer is infected by this malware, then the malware will corrupt all files in the computer. A file in a computer contains zero or more bits. The malware corrupts a file by performing zero or more operations. In one operation, the malware randomly picks two consecutive bits and replaces them with a single bit. The new bit is 11 if both of the replaced bits are 11, or 00 otherwise. For example, the malware might corrupt a file with bits 1101101111011011 as follows:

  1. The malware picks the first and second bits: 11011011101101111011011 \rightarrow 1011011.
  2. The malware picks the second and third bits: 10110111010111011011 \rightarrow 101011.
  3. The malware picks the third and fourth bits: 10101110011101011 \rightarrow 10011.

Alternatively, the malware might first pick the third and fourth bits: 11011011110101111011011 \rightarrow 1101011.

At the start of the day, you have a file containing nn bits, denoted by BB. You spend the day surfing the internet, including checking on your favorite programming contest website, just like many ICPC contestants would do. At the end of the day, the same file contains mm bits, denoted by CC. You want to determine whether this file could have been corrupted by the WannaLaugh malware, or if it must have changed for other reasons.

Input Format

The first line of input contains one integer tt (1t100001 \leq t \leq 10\,000) representing the number of test cases. After that, tt test cases follow. Each of them is presented as follows.

The first line of input contains two integers nn and mm (1mn1000001 \leq m \leq n \leq 100\,000). The second line contains a string with nn characters, each is either 00 or 11, representing the bits BB. The third line contains a string with mm characters, each is either 00 or 11, representing the bits CC.

The sum of nn across all test cases in one input file does not exceed 100000100\,000.

Output Format

For each test case, output yes if the file with bits BB could have been corrupted by the WannaLaugh malware into bits CC, or no otherwise.

3
8 5
11011011
10011
3 3
101
101
3 2
101
00

yes
yes
no

Hint

Explanation for the sample input/output #1

The first test case corresponds to the example from the problem description.

For the second test case, it is possible that the malware performs zero operations.

For the third test case, it is impossible for the malware to corrupt a file with bits 101101 so that it has bits 0000.