CF2110B.Down with Brackets

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

Down with Brackets

In 2077, robots decided to get rid of balanced bracket sequences once and for all!

A bracket sequence is called balanced if it can be constructed by the following formal grammar.

  1. The empty sequence \varnothing is balanced.
  2. If the bracket sequence AA is balanced, then (}A\mathtt{) is also balanced.
  3. If the bracket sequences AA and BB are balanced, then the concatenated sequence ABA B is also balanced.

You are the head of the department for combating balanced bracket sequences, and your main task is to determine which brackets you can destroy and which you cannot.

You are given a balanced bracket sequence represented by a string ss, consisting of the characters ( and ). Since the robots' capabilities are not limitless, they can remove exactly one opening bracket and exactly one closing bracket from the string.

Your task is to determine whether the robots can delete such two brackets so that the string ss is no longer a balanced bracket sequence.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

Each test case consists of a single string ss (2s21052 \leq |s| \leq 2 \cdot 10^5) — a sequence of the characters ( and ).

It is guaranteed that ss is a balanced bracket sequence.

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

Output

For each test case, output "YES" if the robots can make the string stop being a balanced bracket sequence, and "NO" otherwise.

You may 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, it can be shown that the robots will not be able to break the correct bracket sequence.

In the second test case, one of the options for removing brackets is as follows:

(())}\color{red}{\texttt{(}}\texttt{)(}\color{red}{\texttt{)}} \rightarrow \texttt{(()))(, which is not a correct bracket sequence.

In the fourth test case, one of the options for removal is as follows:

(}\color{red}{\texttt{(}}\texttt{))((}\color{red}{\texttt{)}}\texttt{)}\rightarrow \texttt{())((), which is not a correct bracket sequence.

Samples

4
(())
(())()()
()
(())(())
NO
YES
NO
YES

在线编程 IDE

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