description: 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.
solution: #include <bits/stdc++.h>
  using namespace std;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  const int MaxN = 300100;
  const int Mod = 998244353;
  long long N;
  long long rW, rB, lW, lB;
  long long rQ, lQ;
  bool BWexist = false, WBexist = false;
  bool BQexist = false, WQexist = false;
  bool QBexist = false, QWexist = false;
  long long BBnum, WWnum;
  long long QQnum;
  long long fac[MaxN];
  long long mul(long long a, long long b) { return (a * b) % Mod; }
  long long add(long long a, long long b) { return (a + b) % Mod; }
  void precompute_fac() {
    fac[0] = 1;
    for (int i = 1; i < MaxN; i++) {
      fac[i] = mul(fac[i - 1], i);
    }
  }
  long long modpow(long long a, long long b) {
    long long res = 1;
    while (b) {
      if (b & 1) res = mul(res, a);
      a = mul(a, a);
      b >>= 1;
    }
    return res;
  }
  long long inv(long long a) { return modpow(a, Mod - 2); }
  long long binom(long long n, long long k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return mul(fac[n], mul(inv(fac[k]), inv(fac[n - k])));
  }
  void solve() {
    precompute_fac();
    long long onlyWB = 0;
    long long onlyBW = 0;
    long long bad = 0;
    if (BBnum == 0 && WWnum == 0) {
      if (!BWexist && !BQexist && !QWexist) {
        onlyWB = 1;
      }
      if (!WBexist && !QBexist && !WQexist) {
        onlyBW = 1;
      }
      bad = modpow(2, QQnum);
    }
    long long sum = rB + rQ - lW;
    if (lB + lQ - rW != sum) {
      cout << 0 << endl;
      return;
    }
    long long ans = 0;
    for (long long x = max(sum - rQ, (long long)0); x <= min(lQ, sum); x++) {
      long long y = sum - x;
      ans = add(ans, mul(binom(lQ, x), binom(rQ, y)));
    }
    ans = add(ans, Mod - bad);
    ans = add(ans, onlyWB + onlyBW);
    cout << ans << endl;
  }
  void load() {
    cin >> N;
    for (int i = (0); i < (N); i++) {
      char l, r;
      cin >> l >> r;
      if (l == 'W') lW++;
      if (l == 'B') lB++;
      if (l == '?') lQ++;
      if (r == 'W') rW++;
      if (r == 'B') rB++;
      if (r == '?') rQ++;
      if (l == 'W' && r == 'B') {
        WBexist = true;
      }
      if (l == 'B' && r == 'W') {
        BWexist = true;
      }
      if (l == 'B' && r == 'B') {
        BBnum++;
      }
      if (l == 'W' && r == 'W') {
        WWnum++;
      }
      if (l == 'B' && r == '?') {
        BQexist = true;
      }
      if (l == '?' && r == 'B') {
        QBexist = true;
      }
      if (l == 'W' && r == '?') {
        WQexist = true;
      }
      if (l == '?' && r == 'W') {
        QWexist = true;
      }
      if (l == '?' && r == '?') {
        QQnum++;
      }
    }
  }
  int main() {
    ios_base::sync_with_stdio(false);
    int T = 1;
    for (int tt = (0); tt < (T); tt++) {
      load();
      solve();
    }
    return 0;
  }
  