B. Make Binary Strings Equal

B. Make Binary Strings Equal

Time Limit: 0.5 s

Memory Limit: 256.0 MB

Description

You are given two binary strings s and p, both of length n. A binary string is a string consisting only of the characters '0' and '1'.

You are allowed to perform the following operation any number of times (possibly zero):

  • Choose two consecutive indices \(i\) and \(i+1\) (\(1 ≤ i < n\)), and replace the substring s[\(i..i+1\)] with either 01 or 10.

Determine whether it is possible to transform s into p.

Input

  • The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.

  • Each test case consists of three lines:

    • The first line contains an integer n (1 ≤ n ≤ 30) — the length of the strings.

    • The second line contains the binary string s of length n.

    • The third line contains the binary string p of length n.

Output

  • For each test case, print YES if it is possible to transform s into p, otherwise print NO.

Sample

Input Output
5
4
1100
1010
4
1110
1101
2
01
00
1
1
0
2
00
10
YES
YES
NO
NO
YES

First test case :
In the first test case, s = 1100 can be changed to p = 1010 by selecting positions 2 and 3 and replacing 10 with 01.
Hence, the answer is YES.

Fifth test case :
s = 00 and p = 10, we can directly apply one operation on positions 1 and 2 to change 00 → 10.
Hence, the answer is YES.

Information

ID
1233
Difficulty
4
Category
Implementation | Brute_Force Click to Show
Tags
# Submissions
189
Accepted
47
Accepted Ratio
25%
Uploaded By

Related

In following contests:

Happy New Year 2026