P16651 [CodeChef] SWAPCW
普及-
题目描述

Chef is working on his swap-based sorting algorithm for strings.

Given a string S of length N, he wants to know whether he can sort the string using his algorithm.

According to the algorithm, one can perform the following operation on string S any number of times:
Choose some index i (1 ≤ i ≤ N) and swap the i^{th} character from the front and the i^{th} character from the back.
More formally, choose an index i and swap S_{i} and S_{(N+1-i)}.

For example$, \underline{\texttt{d}} \texttt{cb} \underline{\texttt{a}}$ can be converted to $\underline{\texttt{a}} \texttt{cb} \underline{\texttt{d}}$ using one operation where i = 1.

Help Chef find if it is possible to sort the string using any (possibly zero) number of operations.

------ Input Format ------

  • The first line of the input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains N, the length of the string.
  • The second line contains a string S of length N consisting of lowercase letters of the Latin alphabet.

------ Output Format ------

For each test case, print $\texttt{YES}$ if it is possible to sort the string by performing any number of operations. Otherwise, print $\texttt{NO}$.

You may print each character of the string in uppercase or lowercase (for example, the strings $\texttt{YeS}, \texttt{yEs}, \texttt{yes}$ and $\texttt{YES}$ will all be treated as identical).

------ Constraints ------

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{3}$
- Sum of $N$ over all test cases does not exceed $2\cdot10^{3}$.
$S$ consists of lowercase Latin alphabets only.

----- Sample Input 1 ------
3
4
dbca
3
ccc
3
bza
----- Sample Output 1 ------
YES
YES
NO
----- explanation 1 ------
Test case $1$: Chef can sort the string using $1$ operation.
- Choose $i = 1$ and swap $S_{1} = \texttt{d}$ and $S_{4} = \texttt{a}$.
This way, the string becomes $\texttt{abcd}$.

Hence, the string is sorted.

Test case $2$: Chef needs $0$ operations to sort this string as it is already sorted.

Test case $3$: It can be proven that the given string cannot be sorted using any number of operations.

输入格式

见题面

输出格式

见题面

样例输入
3 4 dbca 3 ccc 3 bza
样例输出
YES YES NO