#C4674. Minimum Replacements to Palindrome

    ID: 48238 Type: Default 1000ms 256MiB

Minimum Replacements to Palindrome

Minimum Replacements to Palindrome

You are given a sequence of characters and its length. Your task is to determine the minimum number of character replacements required to transform the sequence into a palindrome.

A string is a palindrome if it reads the same forwards and backwards. For a given string \( S \) of length \( n \), you are required to calculate the minimum number of positions \( i \) (where \( 0 \leq i < \frac{n}{2} \)) such that \( S[i] \neq S[n-i-1] \). Each such mismatch contributes one replacement.

Input Format: The first line contains a single integer \( t \) indicating the number of test cases.
Each test case consists of two lines: the first line contains an integer \( n \) (the length of the string), and the second line contains the string \( S \).

Output Format: For each test case, output a single integer on a new line representing the minimum number of replacements needed to turn the sequence into a palindrome.

inputFormat

The input is read from standard input (stdin) and has the following format:

t
n1
S1
n2
S2
...
nt
St

Here:

  • \( t \) is the number of test cases.
  • For each test case, \( n \) is the length of the string and \( S \) is the sequence of characters.

outputFormat

For each test case, print the minimum number of character replacements required on a separate line to transform the sequence into a palindrome. The output is written to standard output (stdout).

## sample
4
5
HELLO
3
ABC
6
XYZZYX
7
ABCDEFG
2

1 0 3

</p>