#C11660. Reduce String to Empty

    ID: 41001 Type: Default 1000ms 256MiB

Reduce String to Empty

Reduce String to Empty

You are given a string s of length n consisting of lowercase English letters. Your task is to determine whether s can be completely reduced to an empty string by repeatedly removing adjacent pairs of equal characters.

In one operation, you may choose any two adjacent characters that are identical and remove them from the string. This operation can be performed any number of times. If after performing these operations the string becomes empty, then the answer is YES; otherwise, it is NO.

Note: Even though the integer n is provided as input, you can derive it from the string. However, it is included to match the input format.

inputFormat

The input is given via standard input (stdin) and has the following format:

  1. The first line contains a single integer T denoting the number of test cases.
  2. Each of the following T lines contains a test case. Each test case consists of an integer n and a string s separated by a space, where n is the length of the string s.

outputFormat

For each test case, output a single line to standard output (stdout) that contains YES if the string can be reduced to an empty string by repeatedly removing adjacent pairs of identical characters, otherwise output NO.

## sample
5
6 abccba
4 aabb
7 aaabaaa
2 aa
2 ab
YES

YES NO YES NO

</p>