#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

cat mod =998244353;
vector<cat> fac, inv, inv_fac;

cat pw(cat a, cat e) {
	if(e <= 0) return 1;
	cat x =pw(a,e/2);
	x =(x*x)%mod;
	if(e&1) return (x*a)%mod;
	return x;
}

cat getC(int N, int K) {
	if(N < 0 || K < 0 || K > N) return 0;
	cat ret =(inv_fac[K]*inv_fac[N-K])%mod;
	ret =(ret*fac[N])%mod;
	return ret;
}

cat count(int up, int dn, int n) {
	if(n == 0) return (up+dn == 0);
	return getC(up+dn+n-1,n-1);
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int MX =500010;
	fac.resize(MX,1);
	inv.resize(MX,1);
	inv_fac.resize(MX+1,1);
	for(int i =1; i < MX; i++) {
		fac[i] =(i*fac[i-1])%mod;
		inv[i] =pw(i,mod-2);
		inv_fac[i] =(inv[i]*inv_fac[i-1])%mod;
	}

	int N,M;
	string A,B,C,D;
	cin >> N >> M >> A >> B >> C >> D;
	cat ans =0;
	bool zero =1;
	for(int k =0; k < 2; k++) {
		swap(N,M);
		swap(A,C);
		swap(B,D);

		int nL =0, nR =0;
		for(int i =0; i < M; i++) if(C[i] == '1') nL++;
		for(int i =0; i < M; i++) if(D[i] == '1') nR++;
		vector<cat> cL(N,0), cR(N,0);
		int up =0, dn =0;
		for(int i =0; i < N; i++) {
			cL[i] =count(up,dn,nL);
			if(A[i] == '1') up++;
			if(B[i] == '1') dn++;
		}
		up =dn =0;
		for(int i =N-1; i >= 0; i--) {
			cR[i] =count(up,dn,nR);
			if(A[i] == '1') up++;
			if(B[i] == '1') dn++;
		}

		cat akt =0;
		for(int i =N-1; i >= 0; i--) {
			if(A[i] == '1' || B[i] == '1') akt +=cR[i];
			if(A[i] == '1' && B[i] == '1') akt *=2;
			akt %=mod;
			if(A[i] == '1' || B[i] == '1') {
				ans =(ans+akt*cL[i])%mod;
				zero =0;
			}
		}

	}
	if(zero) ans++;
	ans %=mod;
	if(ans < 0) ans +=mod;
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing
