#K4106. Rearrange to Pattern String

    ID: 26781 Type: Default 1000ms 256MiB

Rearrange to Pattern String

Rearrange to Pattern String

Given a string, determine whether it is possible to rearrange its characters to form a pattern string. A pattern string is defined as a string that contains exactly two distinct characters. For example, the string (aabb) can be rearranged as (abab), which satisfies the condition, whereas (abc) cannot be rearranged to meet the requirement. You need to process multiple test cases, reading from standard input and writing the results to standard output.

inputFormat

Input is provided via standard input (stdin). The first line contains an integer (T) (the number of test cases). Each of the next (T) lines contains a non-empty string consisting of lowercase letters.

outputFormat

For each test case, output a single line containing either "YES" if the string can be rearranged to form a pattern string or "NO" otherwise. The result is printed on standard output (stdout).## sample

5
aabb
abc
aabbcc
xyxy
ppqqpp
YES

NO NO YES YES

</p>