409260: GYM103469 L Little LCS

Memory Limit:0 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. Little LCStime limit per test2 secondsmemory limit per test512 mebibytesinputstandard inputoutputstandard output

A string consisting of letters 'A', 'B', 'C' is good if every two adjacent letters are different.

A pair of two good strings $$$(s, t)$$$ of length $$$2n + 1$$$ is awesome if the length of their longest common subsequence is exactly $$$n$$$.

You are given two strings, $$$s$$$ and $$$t$$$, consisting of letters 'A', 'B', 'C' and question marks ('?'). Find the number of ways to replace each '?' with one of 'A', 'B', 'C', so that the pair ($$$s$$$, $$$t$$$) is awesome, modulo $$$998\,244\,353$$$.

Input

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$), the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$).

The second line contains a string $$$s$$$ of length $$$2n+1$$$ consisting of characters 'A', 'B', 'C', '?'.

The third line contains a string $$$t$$$ of length $$$2n+1$$$ consisting of characters 'A', 'B', 'C', '?'.

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

Output

For each test case, output the number of ways to replace each '?' with one of 'A', 'B', 'C' so that the pair $$$(s, t)$$$ is awesome, modulo $$$998\,244\,353$$$.

ExampleInput
5
1
ABA
CBC
1
A?A
C?C
1
???
???
2
AA???
????B
3
?A?B?A?
???????
Output
1
3
24
0
2
Note

In the first test case, pair $$$(\texttt{ABA}, \texttt{CBC})$$$ is awesome.

In the second test case, there are $$$3$$$ ways to replace question marks to get an awesome pair: $$$(\texttt{ABA}, \texttt{CBC})$$$, $$$(\texttt{ACA}, \texttt{CBC})$$$, $$$(\texttt{ABA}, \texttt{CAC})$$$.

加入题单

算法标签: