#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define dalao 998244353
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;
typedef long long ll;
int n,m,K,x,y,fac[N<<2]={1},inv[N<<2],l[N],r[N],ans;
char a[N],b[N],c[N],d[N],s[N];
inline int poww(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%dalao)if(b&1)r=1ll*r*a%dalao;return r;}
inline int C(int a,int b){return a<b||b<0?0:1ll*fac[a]*inv[b]%dalao*inv[a-b]%dalao;}
inline void upd(int& a,int b){a=a+b>=dalao?a+b-dalao:a+b;}
int main(){
	scanf("%d%d%s%s%s%s",&n,&m,a+1,b+1,c+1,d+1),K=max(n,m);
	for(int i=1;i<=(K<<2);i++)fac[i]=1ll*fac[i-1]*i%dalao;
	inv[K<<2]=poww(fac[K<<2],dalao-2);
	for(int i=(K<<2)-1;~i;i--)inv[i]=1ll*inv[i+1]*(i+1)%dalao;
	for(int i=1;i<=n;i++)ans+=a[i]+b[i]-96;
	for(int i=1;i<=m;i++)ans+=c[i]+d[i]-96;
	if(!ans)return puts("1"),0;
	ans=0;
//	---------------------------------------------
	K=0;
	for(int i=1;i<=m;i++)if(d[i]-48+c[i]-48>0)s[++K]=d[i]-48+c[i]-48;
	for(int i=1;i<=n;i++)x+=a[i]-48;
	for(int i=1;i<=K;i++){
		if(x==0&&y==0)l[i]=1;
		else if(x)l[i]=C(x+y-1,x-1);
//		cout<<i<<" "<<l[i]<<" "<<x<<" "<<y<<endl;
		y+=s[i];
	}
	x=y=0;
	for(int i=1;i<=n;i++)x+=b[i]-48;
	for(int i=K;i;i--){
		if(x==0&&y==0)r[i]=1;
		else if(x)r[i]=C(x+y-1,x-1);
		y+=s[i];
	}
	x=0;
	for(int i=1;i<=K;i++){
		upd(x,l[i]);
		if(s[i]==2)upd(x,x);
		upd(ans,1ll*r[i]*x%dalao);
	}
//	---------------------------------------------
	K=x=y=0;
	for(int i=1;i<=n;i++)if(a[i]-48+b[i]-48>0)s[++K]=a[i]-48+b[i]-48;
	for(int i=1;i<=m;i++)x+=c[i]-48;
	for(int i=1;i<=K;i++){
		if(x==0&&y==0)l[i]=1;
		else if(x)l[i]=C(x+y-1,x-1);
		else l[i]=0;
//		cout<<i<<" "<<l[i]<<" "<<x<<" "<<y<<endl;
		y+=s[i];
	}
	x=y=0;
	for(int i=1;i<=m;i++)x+=d[i]-48;
	for(int i=K;i;i--){
		if(x==0&&y==0)r[i]=1;
		else if(x)r[i]=C(x+y-1,x-1);
		else r[i]=0;
		y+=s[i];
	}
	x=0;
	for(int i=1;i<=K;i++){
		upd(x,l[i]);
		if(s[i]==2)upd(x,x);
		upd(ans,1ll*r[i]*x%dalao);
	}
//	---------------------------------------------
	cout<<ans;
	return 0;
}