#K57122. Continuous Lexicographical Sequence

    ID: 30351 Type: Default 1000ms 256MiB

Continuous Lexicographical Sequence

Continuous Lexicographical Sequence

You are given T test cases. In each test case, you are provided an integer n followed by n strings representing codes. Your task is to determine if these codes can be arranged into a continuous lexicographical sequence.

A sequence is defined as continuous if, after sorting the codes in lexicographical order, for every adjacent pair of codes, if the first code is S, then the next code must be exactly S' where:

$$ S' = S[:-1] + \text{chr}(\text{ord}(S[-1]) + 1) $$

For example, if S = "abc", then the expected subsequent code should be "abd". Output YES if the codes follow this property, and NO otherwise.

inputFormat

The input begins with an integer T representing the number of test cases. For each test case:

  • The first line contains an integer n, the number of codes.
  • The next n lines each contain a non-empty string, representing an individual code.

outputFormat

For each test case, output a single line containing either YES or NO based on whether the codes can be arranged into a continuous lexicographical sequence as described.

## sample
3
3
abc
abd
abe
4
abc
abz
abf
abd
2
a
b
YES

NO YES

</p>