human
Write me a Python code to print a single integer — the answer to the problem given the following:
You are given n dominoes. Each domino has a left and a right cell. Each cell can be colored either black or white. Some cells are already colored, while some aren't yet.

The coloring is said to be valid if and only if it is possible to rearrange the dominoes in some order such that for each 1 ≤ i ≤ n the color of the right cell of the i-th domino is different from the color of the left cell of the ((i mod n)+1)-st domino. 

Note that you can't rotate the dominoes, so the left cell always remains the left cell, and the right cell always remains the right cell.

Count the number of valid ways to color the yet uncolored cells of dominoes. Two ways are considered different if there is a cell that is colored white in one way and black in the other. In particular, colorings BW WB and WB BW different (and both invalid).

As this number can be very big, output it modulo 998 244 353.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10^5) — the number of dominoes.

The next n lines describe dominoes. Each line contains two characters which represent the left and the right cell. Character B means that the corresponding cell is black, character W means that the corresponding cell is white, and ? means that the cell is yet to be colored. 

Output

Print a single integer — the answer to the problem.

Examples

Input

1
?W

Output

1

Input

2
??
W?

Output

2

Input

4
BB
??
W?
??

Output

10

Note

In the first test case, there is only one domino, and we need the color of its right cell to be different from the color of its left cell. There is only one way to achieve this.

In the second test case, there are only 2 such colorings:

BB WW and WB WB.
The above is tricky. Write me a correct solution in PYTHON3.
assistant
#Here is Python code to print a single integer — the answer to the problem.

#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

def main():
    MOD = 998244353
    n = int(input())
    lcnt = [0, 0]
    rcnt = [0, 0]
    errorterm = 1
    allBW = 1
    allWB = 1
    for _ in range(n):
        a = input()
        if a[0] == "W":
            lcnt[0] += 1
            allBW = 0
        elif a[0] == "B":
            lcnt[1] += 1
            allWB = 0
        if a[1] == "W":
            rcnt[0] += 1
            allWB = 0
        elif a[1] == "B":
            rcnt[1] += 1
            allBW = 0
        if (a[0] == "W" and a[1] == "W") or (a[0] == "B" and a[1] == "B"):
            errorterm = 0
        elif a[0] == "?" and a[1] == "?":
            errorterm *= 2
            errorterm %= MOD
    combiL = [1]
    combiR = [1]
    nL = n - sum(lcnt)
    nR = n - sum(rcnt)
    for i in range(nL):
        combiL.append(combiL[-1] * (nL - i) * pow(i + 1, MOD - 2, MOD))
        combiL[-1] %= MOD
    for i in range(nR):
        combiR.append(combiR[-1] * (nR - i) * pow(i + 1, MOD - 2, MOD))
        combiR[-1] %= MOD
    
    ans = 0

    for i in range(n + 1):
        target1 = i - lcnt[0]
        target2 = i - rcnt[1]
        if target1 < 0 or target1 > nL or target2 < 0 or target2 > nR:
            continue
        ans += combiL[target1] * combiR[target2]
        ans %= MOD

    print((ans - errorterm + allBW + allWB) % MOD)
        

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def...