CF BUDDY
← Problems·

1994B · Fun Game

1100 · bitmasks, constructive algorithms, greedy

Problem: Vova really loves the XOR operation (denoted as \oplus). Recently, when he was going to sleep, he came up with a fun game.

At the beginning of the game, Vova chooses two binary sequences ss and tt of length nn and gives them to Vanya. A binary sequence is a sequence consisting only of the numbers 00 and 11. Vanya can choose integers l,rl, r such that 1lrn1 \leq l \leq r \leq n, and for all lirl \leq i \leq r simultaneously replace sis_i with sisil+1s_i \oplus s_{i - l + 1}, where sis_i is the ii-th element of the sequence ss.

In order for the game to be interesting, there must be a possibility to win. Vanya wins if, with an unlimited number of actions, he can obtain the sequence tt from the sequence ss. Determine if the game will be interesting for the sequences ss and tt.

Input Format: Each test consists of multiple test cases. The first line contains an integer qq (1q1041 \le q \le 10^{4}) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains a single integer nn (1n21051 \leq n \leq 2 \cdot 10^5) — the length of the sequences ss and tt.

The second line of each test case contains a binary sequence ss of length nn.

The third line of each test case contains a binary sequence tt of length nn.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output "Yes" if the game will be interesting, otherwise output "No".

You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

Note: In the first test case, Vanya will not be able to change the sequence ss with the only possible action of choosing l=r=1l = r = 1.

In the second test case, the sequences ss and tt are already equal.

In the third test case, Vanya can act as follows:

  1. Choose l=3l = 3 and r=5r = 5, then ss will become 101101010\mathtt{101101010}.
  2. Choose l=5l = 5 and r=6r = 6, then ss will become 101111010\mathtt{101111010}.
  3. Choose l=7l = 7 and r=7r = 7, then ss will become 101111110\mathtt{101111110}.

Sample Cases

Case 1

Input

6
1
0
1
7
0110100
0110100
9
100101010
101111110
4
0011
1011
4
0100
0001
8
10110111
01100000

Output

NO
YES
YES
NO
YES
YES

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback