#d2552. 循环子串

循环子串

Cyclic Substring

Problem Description

A string SS is a cyclic substring of another string TT if and only if there exists some kk such that, after cyclically shifting TT right by kk positions to obtain a new string T′T', SS is a substring of T′T'.

For example: abc is a cyclic substring of cefab (cefab shifted right by 22 positions becomes abcef, and abc is a substring of abcef).

A string PP is a fully cyclic string if and only if for any substring HH of it, HreverseH_{\text{reverse}} is a cyclic substring of PP (HreverseH_{\text{reverse}} is the reversal of HH, e.g. abc reversed is cba).

Given a string of length nn, determine whether it is a fully cyclic string.

Input Format

The first line contains a positive integer tt, the number of test cases.

For each test case, the first line contains a positive integer nn, the length of the string. The next line contains a string of length nn, consisting only of lowercase letters.

Output Format

For each test case, if the string is a fully cyclic string, output YES; otherwise output NO. Output a newline between consecutive test cases.

Sample Input

2
4
ccca
11
eeaafbddfaa

Sample Output

YES
NO

Constraints

For all data, 1≤t≤1001 \le t \le 100, 1≤n≤1031 \le n \le 10^3, and ∑n≤103\sum n \le 10^3.

Hint

  1. This problem can be solved with only basic syntax knowledge.
  2. What does "any substring" mean?
  3. If a substring contains another substring, can we just figure out the validity of the larger substring and infer the validity of the smaller one?
  4. Think from larger substrings down to smaller ones: what is the largest substring?