#include <bits/stdc++.h>
using namespace std;
mt19937_64 myrand(chrono::system_clock::now().time_since_epoch().count());
const long long INF = 1e18, P = 998244353, MXN = 1e6 + 5;
const pair<long long, long long> go[] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},
                                         {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
long long n, m, tot, spc;
long long arr[MXN];
template <class T>
T qpow(T x, long long y) {
  T r(1);
  while (y) {
    if (y & 1) r = r * x;
    x = x * x, y >>= 1;
  }
  return r;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
template <class T>
void umx(T &x, T y) {
  x = max(x, y);
}
template <class T>
void umn(T &x, T y) {
  x = min(x, y);
}
long long abs(pair<long long, long long> x) {
  return abs(x.first) + abs(x.second);
}
long long randint(long long l, long long r) {
  uniform_int_distribution<long long> res(l, r);
  return res(myrand);
}
long double randdb(long double l, long double r) {
  uniform_real_distribution<long double> res(l, r);
  return res(myrand);
}
pair<long long, long long> operator+(const pair<long long, long long> &x,
                                     const pair<long long, long long> &y) {
  return pair<long long, long long>(x.first + y.first, x.second + y.second);
}
pair<long long, long long> operator-(const pair<long long, long long> &x,
                                     const pair<long long, long long> &y) {
  return pair<long long, long long>(x.first - y.first, x.second - y.second);
}
pair<long long, long long> operator*(const pair<long long, long long> &x,
                                     const long long &y) {
  return pair<long long, long long>(x.first * y, x.second * y);
}
struct mll {
  long long v;
  explicit mll(long long _v = 0) : v(_v) {}
  long long redu(const long long &x) const {
    if (x < P) return x;
    if (x < (P << 1)) return x - P;
    return x % P;
  }
  explicit operator long long() const { return v; }
  mll operator+(const mll &y) const { return mll(redu(v + y.v)); }
  mll operator-(const mll &y) const { return mll(redu(P + v - y.v)); }
  mll operator*(const mll &y) const { return mll(redu(v * y.v)); }
  mll operator/(const mll &y) const {
    return mll(redu(v * (long long)qpow(y, P - 2)));
  }
  mll &operator=(const mll &y) { return v = y.v, *this; }
  mll &operator+=(const mll &y) { return v = redu(v + y.v), *this; }
  mll &operator-=(const mll &y) { return v = redu(P + v - y.v), *this; }
  mll &operator*=(const mll &y) { return v = redu(v * y.v), *this; }
  mll &operator/=(const mll &y) {
    return v = redu(v * (long long)qpow(y, P - 2)), *this;
  }
  bool operator==(const mll &y) const { return v == y.v; }
  bool operator!=(const mll &y) const { return v != y.v; }
};
template <class T>
struct myvec {
  T *v;
  int sz, dsz;
  myvec() { v = NULL, sz = dsz = 0; }
  ~myvec() { free(v); }
  operator T *() const { return v; }
  T *begin() { return v; }
  T *end() { return v + sz; }
  void rsz(int x) { v = (T *)realloc(v, sizeof(T) * (dsz = sz = x)); }
  void push_back(T x) {
    if (sz == dsz) v = (T *)realloc(v, sizeof(T) * (dsz = dsz << 1 | 1));
    v[sz++] = x;
  }
  void fill(T x) {
    for (int i = 0; i < sz; i++) v[i] = x;
  }
};
char str[MXN][4];
bool match(char *x, const char *y) {
  for (int i = 0; i < 2; i++)
    if (x[i] != y[i] && x[i] != '?') return 0;
  return 1;
}
void solve() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str[i]);
    for (int j = 0; j < 2; j++) {
      if (str[i][j] == 'W')
        tot++;
      else if (str[i][j] == 'B')
        tot--;
      else
        spc++;
    }
  }
  long long tmp = (spc + tot) >> 1;
  mll ans(1);
  if (tmp > spc || tmp < 0) {
    puts("0");
    return;
  }
  for (int i = 0; i < tmp; i++) ans = ans * mll(spc - i);
  for (int i = 1; i <= tmp; i++) ans = ans * qpow((mll)i, P - 2);
  mll del(1);
  long long f = 1, g = 1;
  for (int i = 1; i <= n; i++) {
    long long tmp = match(str[i], "WB") + match(str[i], "BW");
    f &= match(str[i], "WB");
    g &= match(str[i], "BW");
    del *= (mll)tmp;
  }
  ans -= del - (mll)(f + g);
  printf("%lld", (long long)ans);
}
int main() {
  solve();
  return 0;
}

### Prompt

Generate a cpp solution to the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937_64 myrand(chrono::system_clock::now().time_since_epoch().count());
const long long INF = 1e18, P = 998244353, MXN = 1e6 + 5;
const pair<long long, long long> go[] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},
                                         {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
long long n, m, tot, spc;
long long arr[MXN];
template <class T>
T qpow(T x, long long y) {
  T r(1);
  while (y) {
    if (y & 1) r = r * x;
    x = x * x, y >>= 1;
  }
  return r;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
template <class T>
void umx(T &x, T y) {
  x = max(x, y);
}
template <class T>
void umn(T &x, T y) {
  x = min(x, y);
}
long long abs(pair<long long, long long> x) {
  return abs(x.first) + abs(x.second);
}
long long randint(long long l, long long r) {
  uniform_int_distribution<long long> res(l, r);
  return res(myrand);
}
long double randdb(long double l, long double r) {
  uniform_real_distribution<long double> res(l, r);
  return res(myrand);
}
pair<long long, long long> operator+(const pair<long long, long long> &x,
                                     const pair<long long, long long> &y) {
  return pair<long long, long long>(x.first + y.first, x.second + y.second);
}
pair<long long, long long> operator-(const pair<long long, long long> &x,
                                     const pair<long long, long long> &y) {
  return pair<long long, long long>(x.first - y.first, x.second - y.second);
}
pair<long long, long long> operator*(const pair<long long, long long> &x,
                                     const long long &y) {
  return pair<long long, long long>(x.first * y, x.second * y);
}
struct mll {
  long long v;
  explicit mll(long long _v = 0) : v(_v) {}
  long long redu(const long long &x) const {
    if (x < P) return x;
    if (x < (P << 1)) return x - P;
    return x % P;
  }
  explicit operator long long() const { return v; }
  mll operator+(const mll &y) const { return mll(redu(v + y.v)); }
  mll operator-(const mll &y) const { return mll(redu(P + v - y.v)); }
  mll operator*(const mll &y) const { return mll(redu(v * y.v)); }
  mll operator/(const mll &y) const {
    return mll(redu(v * (long long)qpow(y, P - 2)));
  }
  mll &operator=(const mll &y) { return v = y.v, *this; }
  mll &operator+=(const mll &y) { return v = redu(v + y.v), *this; }
  mll &operator-=(const mll &y) { return v = redu(P + v - y.v), *this; }
  mll &operator*=(const mll &y) { return v = redu(v * y.v), *this; }
  mll &operator/=(const mll &y) {
    return v = redu(v * (long long)qpow(y, P - 2)), *this;
  }
  bool operator==(const mll &y) const { return v == y.v; }
  bool operator!=(const mll &y) const { return v != y.v; }
};
template <class T>
struct myvec {
  T *v;
  int sz, dsz;
  myvec() { v = NULL, sz = dsz = 0; }
  ~myvec() { free(v); }
  operator T *() const { return v; }
  T *begin() { return v; }
  T *end() { return v + sz; }
  void rsz(int x) { v = (T *)realloc(v, sizeof(T) * (dsz = sz = x)); }
  void push_back(T x) {
    if (sz == dsz) v = (T *)realloc(v, sizeof(T) * (dsz = dsz << 1 | 1));
    v[sz++] = x;
  }
  void fill(T x) {
    for (int i = 0; i < sz; i++) v[i] = x;
  }
};
char str[MXN][4];
bool match(char *x, const char *y) {
  for (int i = 0; i < 2; i++)
    if (x[i] != y[i] && x[i] != '?') return 0;
  return 1;
}
void solve() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str[i]);
    for (int j = 0; j < 2; j++) {
      if (str[i][j] == 'W')
        tot++;
      else if (str[i][j] == 'B')
        tot--;
      else
        spc++;
    }
  }
  long long tmp = (spc + tot) >> 1;
  mll ans(1);
  if (tmp > spc || tmp < 0) {
    puts("0");
    return;
  }
  for (int i = 0; i < tmp; i++) ans = ans * mll(spc - i);
  for (int i = 1; i <= tmp; i++) ans = ans * qpow((mll)i, P - 2);
  mll del(1);
  long long f = 1, g = 1;
  for (int i = 1; i <= n; i++) {
    long long tmp = match(str[i], "WB") + match(str[i], "BW");
    f &= match(str[i], "WB");
    g &= match(str[i], "BW");
    del *= (mll)tmp;
  }
  ans -= del - (mll)(f + g);
  printf("%lld", (long long)ans);
}
int main() {
  solve();
  return 0;
}

```