#C7736. Balanced Brackets

    ID: 51640 Type: Default 1000ms 256MiB

Balanced Brackets

Balanced Brackets

You are given a sequence of strings, each string consisting of bracket characters: '(', ')', '{', '}', '[' and ']'. The task is to determine whether the sequence of brackets in each string is balanced. A sequence is considered balanced if:

  • Every opening bracket has a corresponding closing bracket of the same type.
  • The brackets are closed in the correct order.

For example, the string {[()]} is balanced, whereas {[(])} is not.

Your program should process multiple bracket sequences. For each sequence, output YES if it is balanced and NO otherwise.

Note: All input should be read from stdin and all output should be printed to stdout.

inputFormat

The first line contains an integer T, the number of bracket sequences to evaluate. Each of the following T lines contains one string S consisting solely of the characters '(', ')', '{', '}', '[' and ']'.

Input is provided via stdin.

outputFormat

For each bracket sequence, output a single line containing either YES if the sequence is balanced, or NO if it is not balanced. The output should be printed to stdout.

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

NO YES YES YES NO NO

</p>