#include<bits/stdc++.h>
#define N 400009
#define ll long long
#define mod 998244353
#define cbn(x,y) ((ll)fac[x]*inv[y]%mod*inv[(x)-(y)]%mod)
using namespace std;

int m,n,a[N],b[N],fac[N],inv[N]; char A[N],B[N],C[N],D[N];
int solve(int m,int n,char *A,char *B,char *C,char *D){
	int i,x,y;
	memset(a,0,sizeof(a)); memset(b,0,sizeof(b));
	a[0]=b[n+1]=1;
	for (i=1,y=0; i<=m; i++) if (A[i]=='1') y++;
	for (i=1,x=0; i<=n; i++){
		if (C[i]=='1') x++;
		if (D[i]=='1') x++;
		a[i]=cbn(x+y,x);
		if (x) a[i]=(a[i]-cbn(x+y-1,x-1)+mod)%mod;
		//cout<<i<<' '<<a[i]<<endl;
	}
	for (i=1,y=0; i<=m; i++) if (B[i]=='1') y++;
	for (i=n,x=0; i; i--){
		if (C[i]=='1') x++;
		if (D[i]=='1') x++;
		b[i]=cbn(x+y,x);
		if (x>0) b[i]=(b[i]-cbn(x+y-1,x-1)+mod)%mod;
		//cout<<i<<' '<<b[i]<<endl;
	}
	int tmp;
	for (i=0,tmp=1; i<=n; i++){
		if (i>0 && C[i]=='1' && D[i]=='1') tmp=(ll)tmp*(mod+1>>1)%mod;
		a[i]=(ll)a[i]*tmp%mod;
		if (i<=n && C[i+1]=='0' && D[i+1]=='0') a[i]=0;
	}
	for (i=1; i<=n; i++) a[i]=(a[i]+a[i-1])%mod;
	for (i=tmp=1; i<=n+1; i++){
		b[i]=(ll)b[i]*tmp%mod;
		if (i<=n && C[i]=='1' && D[i]=='1') tmp=tmp*2%mod;
		if (i>1 && C[i-1]=='0' && D[i-1]=='0') b[i]=0;
	}
	int ans=0;
	for (i=1; i<=n; i++) ans=(ans+(ll)b[i+1]*a[i-1])%mod;
	//cout<<ans<<endl;
	return ans;
}
int main(){
	scanf("%d%d",&m,&n);
	scanf("%s%s%s%s",A+1,B+1,C+1,D+1);
	int i;
	for (i=1; i<=m; i++) if (A[i]=='1' || B[i]=='1') break;
	if (i>m){
		for (i=1; i<=n; i++) if (C[i]=='1' || D[i]=='1') break;
		if (i>n){ puts("1"); return 0; }
	}
	fac[0]=inv[0]=inv[1]=1;
	for (i=1; i<=(m+n<<1); i++) fac[i]=(ll)fac[i-1]*i%mod;
	for (i=2; i<=(m+n<<1); i++) inv[i]=mod-(ll)inv[mod%i]*(mod/i)%mod;
	for (i=2; i<=(m+n<<1); i++) inv[i]=(ll)inv[i-1]*inv[i]%mod;
	printf("%d\n",(solve(m,n,A,B,C,D)+solve(n,m,C,D,A,B))%mod);
	return 0;
}