CF2092B.Lady Bug

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

Lady Bug

As soon as Dasha Purova crossed the border of France, the villain Markaron kidnapped her and placed her in a prison under his large castle. Fortunately, the wonderful Lady Bug, upon hearing the news about Dasha, immediately ran to save her in Markaron's castle. However, to get there, she needs to crack a complex password.

The password consists of two bit strings aa and bb, each of which has a length of nn. In one operation, Lady Bug can choose any index 2in2 \le i \le n and perform one of the following actions:

  1. swap(aia_i, bi1b_{i-1}) (swap the values of aia_i and bi1b_{i-1}), or
  2. swap(bib_i, ai1a_{i-1}) (swap the values of bib_i and ai1a_{i-1}).

Lady Bug can perform any number of operations. The password is considered cracked if she can ensure that the first string consists only of zeros. Help her understand whether or not she will be able to save the unfortunate Dasha.

Input

Each test consists of several test cases. The first line of the input data contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer nn (2n21052 \leq n \leq 2 \cdot 10^5) — the length of the bit strings of the password.

The next two lines contain the bit strings of length nn, aa and bb, which represent the password. Each of the strings contains only the characters 0 and '1'.

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

Output

For each test case, output "YES" if Lady Bug can crack the password after any number of operations; otherwise, output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

Note

In the first test case, the string aa immediately consists only of zeros.

In the second test case, a possible sequence of operations is:

  1. swap(a2, b1)(a_2, \ b_{1})

    0{\color{red}{1}}0001

    {\color{red}{0}}10111

  2. swap(b5, a4)(b_5, \ a_{4})

    000{\color{red}{0}}01

    1101{\color{red}{1}}1

  3. swap(a4, b3)(a_4, \ b_{3})

    000{\color{red}{1}}01

    11{\color{red}{0}}101

  4. swap(a5, b4)(a_5, \ b_{4})

    00000{\color{red}{1}}

    1111{\color{red}{0}}1

Samples

4
3
000
000
6
010001
010111
5
10000
01010
2
11
00
YES
YES
NO
YES

在线编程 IDE

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