Little LCS

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

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)(s, t) of length 2n+12n + 1 is awesome if the length of their longest common subsequence is exactly nn.

You are given two strings, ss and tt, 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 (ss, tt) is awesome, modulo 998,244,353998\\,244\\,353.

입력

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

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

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

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

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

출력

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

힌트

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

In the second test case, there are 33 ways to replace question marks to get an awesome pair: (ABA, CBC), (ACA, CBC), (ABA, CAC).