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: import java.util.*;
  import java.util.Map.Entry;
  
  import java.math.*;
  import java.io.*;
  
  public class Main {
  	public static void main(String[] args) throws FileNotFoundException {
  		InputReader in = new InputReader(System.in);
  		// Scanner in = new Scanner(System.in);
  		// Scanner in = new Scanner(new BufferedReader(new
  		// InputStreamReader(System.in)));
  		PrintWriter out = new PrintWriter(System.out);
  		// InputReader in = new InputReader(new
  		// File("ethan_traverses_a_tree.txt"));
  		// PrintWriter out = new PrintWriter(new
  		// File("ethan_traverses_a_tree-output.txt"));
  
  		final long mod = 998244353;
  
  		int n = in.nextInt();
  		char[][] a = new char[n][2];
  		String[] b = new String[n];
  		for (int i = 0; i < n; i++) {
  			b[i] = in.next();
  			a[i] = b[i].toCharArray();
  		}
  
  		boolean hassame = false;
  		int countw = 0;
  		int countb = 0;
  		int countremain = 0;
  
  		int countkpair = 0;
  		for (int i = 0; i < n; i++) {
  			if (b[i].equals("WW") || b[i].equals("BB")) {
  				hassame = true;
  			}
  			if (b[i].equals("??")) {
  				countkpair++;
  			}
  
  			for (int j = 0; j < 2; j++) {
  				if (a[i][j] == 'W') {
  					countw++;
  				} else if (a[i][j] == 'B') {
  					countb++;
  				} else {
  					countremain++;
  				}
  			}
  		}
  
  		if (countw > n || countb > n) {
  			out.printf("0\n");
  		} else if (countw == n || countb == n) {
  			if (hassame == true) {
  				out.printf("1\n");
  			} else {
  				if (canAllBw(a) || canAllWb(a)) {
  					out.printf("1\n");
  				} else {
  					out.printf("0\n");
  				}
  			}
  		} else {
  			long[] c = new long[countremain + 1];
  			c[0] = 1;
  			for (int i = 1; i < c.length; i++) {
  				long tmp = (countremain - i + 1) * inverse(i, mod) % mod;
  				c[i] = (c[i - 1] * tmp) % mod;
  			}
  
  			int remainw = n - countw;
  			int remainb = n - countb;
  			long ans = c[remainw];
  			if(hassame == false && countkpair > 0) {
  				ans = (ans - powmod(2, countkpair, mod) + mod) % mod;
  			}
  			if (canAllBw(a)) {
  				ans = (ans + 1) % mod;
  			}
  			if (canAllWb(a)) {
  				ans = (ans + 1) % mod;
  			}
  
  			out.printf("%d\n", ans);
  		}
  
  		out.close();
  	}
  
  	static public boolean canAllWb(char[][] a) {
  		for (int i = 0; i < a.length; i++) {
  			if (a[i][0] == 'B' || a[i][1] == 'W') {
  				return false;
  			}
  		}
  
  		return true;
  	}
  
  	static public boolean canAllBw(char[][] a) {
  		for (int i = 0; i < a.length; i++) {
  			if (a[i][0] == 'W' || a[i][1] == 'B') {
  				return false;
  			}
  		}
  
  		return true;
  	}
  
  	static public long inverse(long a, long p) {
  		return powmod(a, p - 2, p);
  	}
  
  	static public long powmod(long a, long n, long mod) {
  		long result = 1;
  		long p = a;
  
  		while (n != 0) {
  			if (n % 2 == 1) {
  				result = (result * p) % mod;
  			}
  			p = (p * p) % mod;
  			n = n / 2;
  		}
  
  		return result;
  	}
  
  	static class InputReader {
  		BufferedReader br;
  		StringTokenizer st;
  
  		public InputReader(File f) {
  			try {
  				br = new BufferedReader(new FileReader(f));
  			} catch (FileNotFoundException e) {
  				e.printStackTrace();
  			}
  		}
  
  		public InputReader(InputStream in) {
  			br = new BufferedReader(new InputStreamReader(in));
  		}
  
  		public String next() {
  			while (st == null || !st.hasMoreTokens()) {
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			}
  			return st.nextToken();
  		}
  
  		public boolean hasNext() {
  			while (st == null || !st.hasMoreTokens()) {
  				String s = null;
  				try {
  					s = br.readLine();
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  				if (s == null)
  					return false;
  				st = new StringTokenizer(s);
  			}
  			return true;
  		}
  
  		public int nextInt() {
  			return Integer.parseInt(next());
  		}
  
  		public long nextLong() {
  			return Long.parseLong(next());
  		}
  
  		public double nextDouble() {
  			return Double.parseDouble(next());
  		}
  	}
  }