logo AlgoBeat OnlineJudge
登录 注册

#215738. [ICPC 2023 Jakarta R] Button Pressing

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given buttons (numbered from to ) and lamps (numbered from to ). Each lamp can either be on or off. Initially, lamp is on if , and off if .

Button is connected to lamp (if ) and lamp (if ). In one move, you can press a button only if lamp is on. When a button is pressed, the state of the lamps connected to this button is toggled. Formally, the lamps will be on if it was off previously, and the lamps will be off if it was on previously. Note that lamp is not connected to button , thus, the state of lamp does not change if button is pressed.

After zero or more moves, you want lamp to be on if , and off if . Determine if it is possible to achieve this task.

输入格式

This problem has multiple test cases. The first line consists of an integer ( ), which represents the number of test cases. Each test case consists of three lines.

The first line of each test case consists of an integer ( ). The sum of over all test cases does not exceed .

The second line of each test case consists of a string of length . Each character of can either be 0 or 1. The -th character represents the initial state of lamp .

The third line of each test case consists of a string of length . Each character of can either be 0 or 1. The -th character represents the desired final state of lamp .

输出格式

For each test case, output YES in a single line if the final state of all lamps can be reached after zero or more moves, or NO otherwise.

样例

样例输入 1

2
4
0101
0100
3
000
010

样例输出 1

YES
NO

样例输入 2

5
7
0101011
1111010
5
11111
00000
4
1101
1101
6
101010
100100
3
000
000

样例输出 2

NO
NO
YES
YES
YES

数据范围与提示

Explanation for the sample input/output #1

For the first test case, by pressing the buttons in sequence, the condition of the buttons changes as: .

For the second test case, you are unable to press any button, hence it is impossible to reach the final state.