Chef is working on his swap-based sorting algorithm for strings.
Given a string of length , 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 any number of times:
- Choose some index and swap the character from the front and the character from the back.
More formally, choose an index and swap and .
For example, can be converted to using one operation where .
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 , denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains , the length of the string.
- The second line contains a string of length consisting of lowercase letters of the Latin alphabet.
Output Format
For each test case, print if it is possible to sort the string by performing any number of operations. Otherwise, print .
You may print each character of the string in uppercase or lowercase (for example, the strings , , and will all be treated as identical).
Constraints
- Sum of over all test cases does not exceed .
- consists of lowercase Latin alphabets only.
Sample Input 1
3
4
dbca
3
ccc
3
bza
Sample Output 1
YES
YES
NO
Explanation
Test case : Chef can sort the string using operation.
- Choose and swap and . This way, the string becomes .
Hence, the string is sorted.
Test case : Chef needs operations to sort this string as it is already sorted.
Test case : It can be proven that the given string cannot be sorted using any number of operations.
No comments:
Post a Comment