Under construction

Still being built. Things may change

Little LCS

Time limit2sMemory limit512 MB

Summary
Count the ways to fill the question marks in two good ternary strings of length 2n+1 so that their LCS is exactly n.
Level

Hard8 of 10

Topics
Combinatorics, String, Dynamic programming
Solved
No attempts yet

Statement

A string made of the letters A, B, and C is good if every two adjacent letters are different.

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

You are given two strings, ss and tt, made of the letters A, B, C and question marks (?). Count the ways to replace each ? with A, B, or C so that the pair (s,t)(s, t) is awesome. Output the count modulo 998 244 353998\,244\,353.

Input

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

The first line of each test case contains a single integer nn (1≤n≤1061 \le n \le 10^6). The second line contains a string ss of length 2n+12n+1, and the third line contains a string tt of length 2n+12n+1. Both strings consist of A, B, C, and ?.

The sum of nn over all test cases does not exceed 10610^6.

Output

For each test case, print the number of ways to replace the question marks so that (s,t)(s, t) is awesome, modulo 998 244 353998\,244\,353, on its own line.

Hint

In the first test case, the pair (ABA, CBC) is awesome.

In the second test case, there are 3 ways to replace the question marks so that the pair is awesome: (ABA, CBC), (ACA, CBC), and (ABA, CAC).

Examples1

  1. Example 1

    Input
    5
    1
    ABA
    CBC
    1
    A?A
    C?C
    1
    ???
    ???
    2
    AA???
    ????B
    3
    ?A?B?A?
    ???????
    
    Expected output
    1
    3
    24
    0
    2