#P11749. 「TPOI-1C」Standard Problem.

「TPOI-1C」Standard Problem.

Description

As a contest reviewer for a well-known CP platform, you often receive standard problem submissions.

Having overused replies like "quite standard" and "somewhat standard", you decide to try something new.

First, you write your review ss (a lowercase English string). To emphasize how standard the problem is, you concatenate ss k1k-1 times to form the final reply t=skt = s^k.

The submitter defines the weirdness of a reply as the number of palindromic substrings in it. Your task is to compute the weirdness of tt modulo 998244353998244353.

Formally, given string ss and integer kk, find the number of distinct palindromic substrings (counted by position) in sks^k (the concatenation of kk copies of ss), modulo 998244353998244353.

Input Format

This problem contains multiple test cases.

The first line contains an integer tt (1t104)(1 \le t \le 10^4) indicating the number of test cases.

For each test case:

  • The first line contains two integers n,kn, k (1n3×106, 1k109)(1 \le n \le 3 \times 10^6,\ 1 \le k \le 10^9) representing the string length and concatenation count.
  • The second line contains a lowercase English string ss of length nn.

The sum of nn across all test cases in a single input does not exceed 3×1063 \times 10^6.

Output Format

For each test case, output one integer representing the answer modulo 998244353998244353.

3
4 2
abab
1 1
a
30 1
abaababaababaababaababaababaab

20
1
128

Hint

For the first sample input, t=s2=ababababt = s^2 = \texttt{abababab} contains 20 palindromic substrings.

For the third sample input, the resulting string is (abaab)6(\texttt{abaab})^6.

Constraints

This problem uses bundled tests. You must pass all test cases in a subtask to receive points.

Subtask 1 contains samples and is worth 0 points.

Subtask Points nn \le kk \le
2 5 2 10910^9
3 30 3×1063 \times 10^6
4 2000 10910^9
5 35 3×1063 \times 10^6
  • Subtask 3 guarantees k3×106\sum k \le 3 \times 10^6.
  • Subtask 4 guarantees n22.5×107\sum n^2 \le 2.5 \times 10^7.

Translated by DeepSeek R1