#P9717. [EC Final 2022] Binary String

[EC Final 2022] Binary String

题目描述

You are given a binary string a0a1a2…an−1a_0a_1a_2\dots a_{n-1} arranged on a cycle. Each second, you will change every 0101 to 1010 simultaneously. In other words, if ai=0a_i = 0 and a(i+1) mod n=1a_{(i+1) \bmod n} = 1, you swap aia_i and a(i+1) mod na_{(i+1)\bmod n}. For example, we will change 100101110\texttt{100101110} to 001010111\texttt{001010111}.

You need to answer how many different strings will occur in infinite seconds, modulo 998244353998244353.

Note: Two strings a0a1…an−1a_0a_1\dots a_{n-1} and b0b1…bn−1b_0b_1\dots b_{n-1} are different if there exists an integer i∈{0,1,…,n−1}i\in \{0,1,\ldots, n-1\} such that ai≠bia_i\neq b_i. Thus, the cyclic shifts of a string may be different from the original string.

输入格式

The first line contains an integer TT (1≤T≤106)(1\leq T\leq 10^6) −- the number of test cases.

For each test case, the first line contains a binary string a0a1…an−1a_0 a_1 \dots a_{n-1} (ai∈{0,1})(a_i \in \{0, 1\}).

It is guaranteed that the sum of lengths of strings over all test cases does not exceed 10710^7.

输出格式

For each test case, output one integer representing the answer in one line.

3
1
001001
0001111
1
3
9