#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, MOD = 998244353;
char A[N], B[N], C[N], D[N];
int L[N], R[N], f[3 * N], rf[3 * N];
int mpow(int x, int n) {
	int res = 1;
	while (n) {
		if (n & 1) res = 1LL * res * x % MOD;
		x = 1LL * x * x % MOD;
		n >>= 1;
	}
	return res;
}
int choose(int n, int m) {
	return 1LL * f[n] * rf[n - m] % MOD * rf[m] % MOD;
}
int work(int n, int m, char AA[N], char BB[N], char CC[N], char DD[N]) {
	static char A[N], B[N], C[N], D[N];
	int nn = 0, mm = 0;
	for (int i = 1; i <= n; ++ i) {
		if (AA[i] == '1' || BB[i] == '1') {
			nn ++;
			A[nn] = AA[i];
			B[nn] = BB[i];
		}
	}
	for (int i = 1; i <= m; ++ i) {
		if (CC[i] == '1' || DD[i] == '1') {
			mm ++;
			C[mm] = CC[i];
			D[mm] = DD[i];
		}
	}
	n = nn, m = mm;
	int rl = 0, rr = 0;
	for (int i = 1; i <= n; ++ i) {
		rl += A[i] == '1';
		rr += B[i] == '1';
	}
	L[0] = 1;
	int x = 0, y = 0;
	for (int i = 1; i <= m; ++ i) {
		x += C[i] == '1';
		y += D[i] == '1';
		L[i] = (rl == 0) ? 0 : choose(x + y + rl - 1, rl - 1);
	}
	x = y = 0;
	R[m + 1] = 1;
	for (int i = m; i >= 1; -- i) {
		x += C[i] == '1';
		y += D[i] == '1';
		R[i] = (rr == 0) ? 0 : choose(x + y + rr - 1, rr - 1);
	}
	int ans = 0, tmp = 1;
	for (int i = 1; i <= m; ++ i) {
		tmp = 1LL * tmp * (C[i] == '1' && D[i] == '1' ? 2 : 1) % MOD;
		(ans += 1LL * tmp * R[i + 1] % MOD) %= MOD;
		tmp = (tmp + L[i]) % MOD;
	}
	return ans;
}
int main() {
	f[0] = 1;
	for (int i = 1; i < 3 * N; ++ i) f[i] = 1LL * f[i - 1] * i % MOD;
	rf[3 * N - 1] = mpow(f[3 * N - 1], MOD - 2);
	for (int i = 3 * N - 2; i >= 0; -- i) rf[i] = 1LL * rf[i + 1] * (i + 1) % MOD;
	int n, m;
	scanf("%d%d", &n, &m);
	scanf("%s%s%s%s", A + 1, B + 1, C + 1, D + 1);
	int tot = 0;
	for (int i = 1; i <= n; ++ i) tot += A[i] == '1';
	for (int i = 1; i <= n; ++ i) tot += B[i] == '1';
	for (int i = 1; i <= m; ++ i) tot += C[i] == '1';
	for (int i = 1; i <= m; ++ i) tot += D[i] == '1';
	if (tot == 0) return 0 * puts("1");
	int ans = work(n, m, A, B, C, D);
	reverse(A + 1, A + 1 + n);
	reverse(B + 1, B + 1 + n);
	(ans += work(m, n, D, C, A, B)) %= MOD;
	printf("%d\n", ans);
}

