Codeforces Round 968 (Div. 2)
A
Turtle and Good Strings
Codeforces
800
原题
←B →
翻译中…

Turtle thinks a string $s$ is a good string if there exists a sequence of strings $t_1, t_2, \ldots, t_k$ ($k$ is an arbitrary integer) such that:

翻译中…
  • $k \ge 2$.
  • $s = t_1 + t_2 + \ldots + t_k$, where $+$ represents the concatenation operation. For example, $\texttt{abc} = \texttt{a} + \texttt{bc}$.
  • For all $1 \le i \lt j \le k$, the first character of $t_i$ isn't equal to the last character of $t_j$.
翻译中…

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

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

The second line of each test case contains a string $s$ of length $n$, consisting of lowercase Latin letters.

翻译中…

Output

翻译中…

For each test case, output "YES" if the string $s$ 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 $\texttt{a}, \texttt{a}$ satisfies the condition $s = t_1 + t_2 + \ldots + t_k$, but the first character of $t_1$ is equal to the last character of $t_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 $\texttt{ab}, \texttt{cb}$ satisfies all of the conditions.

翻译中…

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

翻译中…

样例

Input #1
4
2
aa
3
aba
4
abcb
12
abcabcabcabc
Output #1
No
nO
Yes
YES
InputCopy OutputCopy
题目信息
题号
2003A
时间限制
1 s
内存限制
256 MB
标签
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。