Statement : C. Zhily and Bracket Swapping
Deep in the wilderness, Zhily and Jily discovered two sequences composed of brackets. Each sequence carries some logical structure, but neither of them is necessarily a regular bracket sequence on its own. They found that by swapping brackets between the two sequences, they could repair them. They wish to make both sequences regular bracket sequences by swapping brackets between them.
A regular bracket sequence is a sequence consisting of ‘(’ and ‘)’, which can be turned into a valid math expression by inserting 1 and + any number of times into the sequence. For example, the sequence “()(()())” is a regular bracket sequence, while “())((” or “(()” are not regular bracket sequences.
You are given two bracket sequences $a$ and $b$ of even length $n$. You can perform the following operation any number of times:
- Choose a position $i$ ($1 \leq i \leq n$) and swap $a_i$ and $b_i$.
Determine whether you can turn both $a$ and $b$ into regular bracket sequences.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2 \leq n \leq 2\cdot 10^5$, $n$ is even) — the length of the strings $a$ and $b$.
The second line of each test case contains a sequence $a$ of length $n$ consisting only of characters ‘(’ and ‘)’.
The third line of each test case contains a sequence $b$ of length $n$ consisting only of characters ‘(’ and ‘)’.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
For each test case, output “YES” if you can turn both $a$ and $b$ into a regular bracket sequences, “NO” otherwise. You can output “YES” and “NO” in any case (for example, “yES”, “yes”, and “Yes” will be recognized as a positive response).
Input
7
2
()
()
4
))((
(())
4
((((
))))
4
()()
(())
6
(((())
()()))
8
()()()()
(((())))
4
((((
((((
Output
YES
NO
NO
YES
YES
YES
NO
Note
In the first, fourth, and sixth test cases, both $a$ and $b$ are initially regular bracket sequences.
In the second and third test cases, either $a_1$ or $b_1$ will be ‘)’, which makes it impossible for them to be regular.
In the fifth test case, the final sequences may be $\texttt{(((}\color{red}{\texttt{)}}\texttt{))}$ and $\texttt{()(}\color{red}{\texttt{(}}\texttt{))}$, where the brackets to be swapped are colored red.