#K94722. Rotation Pairs

    ID: 38705 Type: Default 1000ms 256MiB

Rotation Pairs

Rotation Pairs

Given a set of strings, determine whether there exists at least one pair of strings that are rotations of each other. Two strings (s_1) and (s_2) are considered rotations if they have the same length and (s_2) appears as a substring of (s_1+s_1). For example, "abc" and "bca" are rotations since "bca" is a substring of "abcabc". The input consists of multiple test cases. For each test case, print YES if at least one rotational pair exists, otherwise print NO.

inputFormat

The first line contains an integer (T) denoting the number of test cases. Each test case begins with an integer (N), the number of strings, followed by a line containing (N) space-separated strings.

outputFormat

For each test case, output a single line containing YES if there exists at least one pair of strings that are rotations of each other, otherwise output NO.## sample

1
3
abc bca xyz
YES

</p>