Codeforces Round 1082 (Div. 1)
E
ABBA Counting
Codeforces
2900
原题
← DF1 →
翻译中…

You are given a string $T$ of length $n$ ($n$ is even), which consists of 'a', 'b', and '?'.

翻译中…

Please count the strings $S$ which satisfy the following conditions:

翻译中…
  • $|S|=n$;
  • $S_i$ is either 'a' or 'b' for all $1 \le i \le n$;
  • $S_i=T_i$ for all $1 \le i \le n$ such that $T_i$ is not '?';
  • There exist two (possibly empty) strings $A$ and $B$ such that $S=A+B+B+A$. Here, $+$ denotes string concatenation.
翻译中…

As the answer may be inexplicably huge, you are only asked to compute 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^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 400\,000$, $n$ is even).

翻译中…

The second line of each test case contains a string $T$ of length $n$, consisting of 'a', 'b', and '?'.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $400\,000$.

翻译中…

Output

翻译中…

For each test case, output the answer modulo $998\,244\,353$ on a separate line.

翻译中…

Note

翻译中…

For the fifth test case, there are $10$ corresponding strings which are as follows:

翻译中…
  1. "aaaabaaaaaba"
  2. "aaaabbaaabba"
  3. "aaabbaaaabba"
  4. "aaabbbaabbba"
  5. "abaabbbaabba"
  6. "ababbbbabbba"
  7. "baaabaaababa"
  8. "baaababaaaba"
  9. "baaabbaabbba"
  10. "baabbabaabba"
翻译中…

样例

Input #1
6
2
a?
2
??
4
a??a
4
ab??
12
??a?b??a??ba
12
?ab???b??a??
Output #1
1
2
2
2
10
22
InputCopy OutputCopy
题目信息
题号
2201E
时间限制
3.5 s
内存限制
256 MB
标签
FFT
数学
数论
字符串

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