Codeforces Global Round 28
I2
Kevin and Puzzle (Hard Version)
Codeforces
3500
原题
← I1→
翻译中…

This is the hard version of the problem. The difference between the versions is that in this version, you need to count the number of good arrays. You can hack only if you solved all versions of this problem.

翻译中…

Kevin is visiting the Red Church, and he found a puzzle on the wall.

翻译中…

For an array $ a $, let $ c(l,r) $ indicate how many distinct numbers are among $ a_l, a_{l+1}, \ldots, a_r $. In particular, if $ l \gt r $, define $ c(l,r) = 0 $.

翻译中…

You are given a string $ s $ of length $ n $ consisting of letters $ \texttt{L} $ and $ \texttt{R} $ only. Let a non-negative array $ a $ be called good, if the following conditions hold for $ 1 \leq i \leq n $:

翻译中…
  • if $s_i=\replacedVerb {L}$, then $c(1,i-1)=a_i$;
  • if $s_i=\replacedVerb {R}$, then $c(i+1,n)=a_i$.
翻译中…

You need to count the number of good arrays $a$. Since the answer may be large, you only need to output the answer modulo $998\,244\,353$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1\le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2\leq n\leq 2\cdot 10^5$) — the length of string $s$.

翻译中…

The second line of each test case contains a string $s$ with a length $n$, containing only English uppercase letters $\replacedVerb {L}$ and $\replacedVerb {R}$.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output the number of good arrays modulo $998\,244\,353$.

翻译中…

Note

翻译中…

All arrays satisfying the conditions can be found in the easy version of this problem.

翻译中…

样例

Input #1
4
3
LLR
3
RRL
4
RRLR
5
LLRLR
Output #1
1
2
0
1
InputCopy OutputCopy
题目信息
题号
2048I2
时间限制
6 s
内存限制
512 MB
标签
位运算
FFT
数学

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