ByteMonk logo
All problems

easy · 409 tests

Balanced Brackets

A string of brackets ()[]{} is balanced when every opening bracket is closed by the same kind of bracket in the correct order. For each of t strings, print YES if it is balanced and NO otherwise.

Input

Line 1: t (1 <= t <= 1000). Then t lines, each a non-empty string of length up to 10^5 made only of ()[]{}.

Output

t lines, YES or NO.

Samples

Input 1

1
()[]{}

Output 1

YES

Input 2

1
([)]

Output 2

NO

Input 3

1
{[]}

Output 3

YES

Input 4

1
((

Output 4

NO

Scoring

  1. Basic correctness20 pts
  2. Edge cases15 pts
  3. Random small20 pts
  4. Random large15 pts
  5. Adversarial10 pts
  6. Performance20 pts
2s · 256 MB
Balanced Brackets · Coding · ByteMonk