#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200500
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
const int MOD = 998244353;
int N,M;
char a[4][MAXN];
int fac[MAXN * 2],invfac[MAXN * 2],f[MAXN],b[MAXN],sum[4][MAXN],s[MAXN];
int pw[MAXN],ipw[MAXN],ans;
int inc(int a,int b) {
	return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
	return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
	int res = 1,t = x;
	while(c) {
		if(c & 1) res = mul(res,t);
		t = mul(t,t);
		c >>= 1;
	}
	return res;
}
void update(int &x,int y) {
	x = inc(x,y);
}
int C(int n,int m) {
	if(n < m) return 0;
	return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
void CalcV() {
	memset(f,0,sizeof(f));
	memset(b,0,sizeof(b));
	memset(s,0,sizeof(s));
	int X = sum[0][N],Y,Z;
	for(int i = 0 ; i <= M ; ++i) {
		if(a[2][i + 1] == '0' && a[3][i + 1] == '0') continue;
		Y = sum[2][i],Z = sum[3][i];
		if(!X) {
			if(Y == 0 && Z == 0) f[i] = 1;
			else f[i] = 0;
		}
		else {
			f[i] = C(X + Y + Z - 1,X - 1);
		}
	}
	X = sum[1][N];
	for(int i = M + 1 ; i >= 1 ; --i) {
		if(a[2][i - 1] == '0' && a[3][i - 1] == '0') continue;
	 	Y = sum[2][M] - sum[2][i - 1],Z = sum[3][M] - sum[3][i - 1];
		if(!X) {
			if(Y == 0 && Z == 0) b[i] = 1;
			else b[i] = 0;
		}
		else {
			b[i] = C(X + Y + Z - 1,X - 1);
		}
	}
	for(int i = 1 ; i <= M ; ++i) s[i] = s[i - 1] + (a[2][i] == '1' && a[3][i] == '1');
	for(int i = 0 ; i <= M ; ++i) {
		f[i] = mul(f[i],ipw[s[i]]);
	}
	for(int i = M + 1 ; i >= 1 ; --i) {
		b[i] = inc(b[i + 1],mul(b[i],pw[s[i - 1]]));
	}
	for(int i = 1 ; i <= M ; ++i) {
		update(ans,mul(f[i - 1],b[i + 1]));
	}
}
void CalcH() {
	memset(f,0,sizeof(f));
	memset(b,0,sizeof(b));
	memset(s,0,sizeof(s));
	int X = sum[2][M],Y,Z;
	for(int i = 0 ; i <= N ; ++i) {
		if(a[0][i + 1] == '0' && a[1][i + 1] == '0') continue;
		Y = sum[0][i],Z = sum[1][i];
		if(!X) {
			if(Y == 0 && Z == 0) f[i] = 1;
			else f[i] = 0;
		}
		else {
			f[i] = C(X + Y + Z - 1,X - 1);
		}
	}
	X = sum[3][M];
	for(int i = N + 1 ; i >= 1 ; --i) {
		if(a[0][i - 1] == '0' && a[1][i - 1] == '0') continue;
		Y = sum[0][N] - sum[0][i - 1],Z = sum[1][N] - sum[1][i - 1];
		if(!X) {
			if(Y == 0 && Z == 0) b[i] = 1;
			else b[i] = 0;
		}
		else {
			b[i] = C(X + Y + Z - 1,X - 1);
		}
	}
	for(int i = 1 ; i <= N ; ++i) s[i] = s[i - 1] + (a[0][i] == '1' && a[1][i] == '1');
	for(int i = 0 ; i <= N ; ++i) {
		f[i] = mul(f[i],ipw[s[i]]);
	}
	for(int i = N + 1 ; i >= 1 ; --i) {
		b[i] = inc(b[i + 1],mul(b[i],pw[s[i - 1]]));
	}
	for(int i = 1 ; i <= N ; i++) {
		update(ans,mul(f[i - 1],b[i + 1]));
	}
}
void Solve() {
	read(N);read(M);
	for(int i = 0 ; i <= 3 ; ++i) scanf("%s",a[i] + 1);
	for(int i = 0 ; i <= 3 ; ++i) {
		int T = (i <= 1 ? N : M);
		for(int j = 1 ; j <= T ; ++j) {
			sum[i][j] = sum[i][j - 1] + (a[i][j] == '1');
		}
	}
	int T = 2 * (N + M) + 10;
	fac[0] = 1;
	for(int i = 1 ; i <= T ; ++i) {
		fac[i] = mul(fac[i - 1],i);
	}
	invfac[T] = fpow(fac[T],MOD - 2);
	for(int i = T - 1 ; i >= 0 ; --i) {
		invfac[i] = mul(invfac[i + 1],i + 1);
	}
	pw[0] = 1;
	T = max(N,M);
	for(int i = 1 ; i <= T ; ++i) {
		pw[i] = mul(pw[i - 1],2);
	}
	ipw[0] = 1;
	for(int i = 1 ; i <= T ; ++i) {
		ipw[i] = mul(ipw[i - 1],(MOD + 1) / 2);
	}
	CalcV();
	CalcH();
	if(!sum[0][N] && !sum[1][N] && !sum[2][M] && !sum[3][M]) ans = 1;
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 10112