#P10296. Heavy and Light Letters Alternation

    ID: 12297 Type: Default 1000ms 256MiB

Heavy and Light Letters Alternation

Heavy and Light Letters Alternation

Given a string containing only lowercase letters, we define a letter as heavy if it appears more than once in the string, and light if it appears exactly once. For each given string, determine whether the heavy and light letters alternate. That is, the string must satisfy one of the following two patterns (using 1-indexed positions):

  • Every letter in an odd position is heavy and every letter in an even position is light.
  • Every letter in an odd position is light and every letter in an even position is heavy.

If one of these two conditions holds, output YES; otherwise, output NO.

inputFormat

The first line contains an integer T (1 ≤ T ≤ 105), the number of test cases. Each test case consists of one line containing a non-empty string s consisting of only lowercase letters.

outputFormat

For each test case, print a single line containing YES if the heavy and light letters alternate as described, or NO otherwise.

sample

1
a
YES