CF2003A.Turtle and Good Strings

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Turtle and Good Strings

Turtle thinks a string ss is a good string if there exists a sequence of strings t1,t2,,tkt_1, t_2, \ldots, t_k (kk is an arbitrary integer) such that:

  • k2k \ge 2.
  • s=t1+t2++tks = t_1 + t_2 + \ldots + t_k, where ++ represents the concatenation operation. For example, abc} = \texttt{a} + \texttt{bc.
  • For all 1i<jk1 \le i \lt j \le k, the first character of tit_i isn't equal to the last character of tjt_j.

Turtle is given a string ss consisting of lowercase Latin letters. Please tell him whether the string ss is a good string!

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains a single integer nn (2n1002 \le n \le 100) — the length of the string.

The second line of each test case contains a string ss of length nn, consisting of lowercase Latin letters.

Output

For each test case, output "YES" if the string ss is a good string, and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first test case, the sequence of strings a}, \texttt{a satisfies the condition s=t1+t2++tks = t_1 + t_2 + \ldots + t_k, but the first character of t1t_1 is equal to the last character of t2t_2. It can be seen that there doesn't exist any sequence of strings which satisfies all of the conditions, so the answer is "NO".

In the third test case, the sequence of strings ab}, \texttt{cb satisfies all of the conditions.

In the fourth test case, the sequence of strings abca}, \texttt{bcab}, \texttt{cabc satisfies all of the conditions.

Samples

4
2
aa
3
aba
4
abcb
12
abcabcabcabc
No
nO
Yes
YES

在线编程 IDE

建议全屏模式获得最佳体验