#P10877. 「KDOI-07」n1gr tS0i

「KDOI-07」n1gr tS0i

Background

As everyone knows, Little T does not like 01 string problems, so Little R made another problem about 01 strings.

Problem Description

There is a 01\tt 01 string SS of length nn. You need to perform exactly nn operations on SS. In each operation, choose 1l<rn1 \le l \color{red}< \color{normal} r \le n, and then flip SlrS_{l\dots r} bit by bit. Here, “flip bit by bit” means that all 0\tt 0 in SlrS_{l\dots r} become 1\tt 1 at the same time, and all 1\tt 1 become 0\tt 0 at the same time.

After nn operations, find the number of all possible distinct strings SS. Since the answer may be very large, output it modulo 998244353998244353.

Input Format

This problem has multiple test cases.

The first line contains an integer TT describing the number of test cases. For each test case:

  • The first line contains an integer nn.
  • The next line contains a 01\tt 01 string SS of length nn.

Output Format

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

2
2
01
30
101001001010100110101101011110

1
75497471

Hint

Sample Explanation

  • For n=2n = 2, S=01S = \tt 01, we will find that in each operation we can only choose l=1,r=2l = 1, r = 2, that is, flipping the whole string. Therefore, after 22 operations we can only get 01\tt 01, so the answer is 11.
  • For the second test case, we cannot give you a clear answer for now.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} nn\le Score
11 44 3030
22 10510^5 7070

For all testdata, it is guaranteed that 2n1052 \le n \le 10^5, n106\sum n \le 10^6, and 1T1041 \le T \le 10^4.

Translated by ChatGPT 5