Problem2224--abc242e - (∀x∀)

2224: abc242e - (∀x∀)

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 500500 points

Problem Statement

Solve the following problem for TT test cases.
Given an integer NN and a string SS, find the number of strings XX that satisfy all of the conditions below, modulo 998244353998244353.
  • XX is a string of length NN consisting of uppercase English letters.
  • XX is a palindrome.
  • X \le SXS in lexicographical order.
    • That is, X=SX=S or XX is lexicographically smaller than SS.

Constraints

  • 1 \le T \le 2500001T250000
  • NN is an integer between 11 and 10^6106 (inclusive).
  • In a single input, the sum of NN over the test cases is at most 10^6106.
  • SS is a string of length NN consisting of uppercase English letters.

Input

Input is given from Standard Input in the following format:
TT\mathrm{case}_1case1\mathrm{case}_2case2\vdots\mathrm{case}_TcaseT
Here, \mathrm{case}_icasei represents the ii-th test case.
Each test case is in the following format:
NNSS

Output

Print TT lines. The ii-th line should contain the answer for the ii-th test case as an integer.

Sample Input Copy

5
3
AXA
6
ABCZAZ
30
QWERTYUIOPASDFGHJKLZXCVBNMQWER
28
JVIISNEOXHSNEAAENSHXOENSIIVJ
31
KVOHEEMSOZZASHENDIGOJRTJVMVSDWW

Sample Output Copy

24
29
212370247
36523399
231364016

HINT

This input contains five test cases.

Test case #1:
The 2424 strings satisfying the conditions are AAA,, ABA,, ACA,...,,..., AXA.

Test case #2:
SS may not be a palindrome.

Test case #3:
Be sure to find the count modulo 998244353998244353.

Source/Category