#C893. Balanced Parentheses Checker

    ID: 52966 Type: Default 1000ms 256MiB

Balanced Parentheses Checker

Balanced Parentheses Checker

You are given a string consisting solely of the characters '(', ')', '{', '}', '[' and ']'. Your task is to determine whether the given string has balanced parentheses. A string is considered to have balanced parentheses if every opening bracket has a corresponding closing bracket in the correct order.

The problem requires you to process multiple test cases. For each test case, check if the sequence of parentheses in the string is balanced. For example, the string {[()]} is balanced while the string ((()) is not.

For any string, output YES if the parentheses are balanced, and NO otherwise. All formulas and conditions, if mentioned, are in \(\LaTeX\) format. In this problem the condition can be formally stated as:

\( S \text{ is balanced } \iff \forall i, \; S[i] \text{ is matched with a corresponding } S[j] \text{, where } j > i \)

inputFormat

The first line of input contains an integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains a non-empty string composed only of the characters '(', ')', '{', '}', '[' and ']'.

Note: Each string is provided on a separate line.

outputFormat

For each test case, output a single line containing either YES if the string has balanced parentheses or NO otherwise.

The output should have exactly \(T\) lines corresponding to the \(T\) test cases.

## sample
4
{}
{[()]}
{[]}
((())
YES

YES YES NO

</p>