Pinely Round 5 (Div. 1 + Div. 2)
E
Left is Always Right
Codeforces
2400
原题
← DF →
翻译中…

Consider a binary string of length $n$ and an odd number $k$. We will call the binary string good if for each substring of length $k$, the leftmost character of the substring occurs more than the other.

翻译中…

For example, if $k = 3$, 000101 is a good string, because for all substrings of length 3 (000, 001, 010, and 101) the first character of the substring occurs more than the other character. On the other hand, 1011 is not good, because the property is false for 011.

翻译中…

Given a pattern of length $n$ consisting of characters 0, 1 and ?, find the number of ways to replace question marks with 0 or 1, such that the resulting binary string is good. Since the answer may be large, find it modulo $998\,244\,353$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($3 \le k \le n \le 10^5$, $k$ is odd). The second line contains $n$ characters 0, 1 or ? — the pattern.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, print the number of ways to replace ? with 0 or 1 such that the resulting string is good, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first example, three valid ways to make the pattern good are 00000, 00001, and 00101. In the second example, the only invalid way (out of 16 total ways) is 1001001.

翻译中…

样例

Input #1
3
5 3
0??0?
7 7
1??1??1
9 5
?????????
Output #1
3
15
46
InputCopy OutputCopy
题目信息
题号
2161E
时间限制
2 s
内存限制
512 MB
标签
组合数学
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。