#include<cstdio>
#include<cstdlib>
#include<cstring>
#define llong long long
using namespace std;

const int N = 2e5;
const int P = 998244353;
llong fact[N*4+3],finv[N*4+3];
char sa[N+3],sb[N+3],sc[N+3],sd[N+3];

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	}
	return ret;
}
llong comb(llong x,llong y) {return x<0 || y<0 || x<y ? 0ll : fact[x]*finv[y]%P*finv[x-y]%P;}

llong solve(int n,int m,char s1[],char s2[],char s3[],char s4[])
{
	int cnt1 = 0,cnt2 = 0,cnt3 = 0,cnt4 = 0,cur3 = 0,cur4 = 0;
	for(int i=1; i<=n; i++) {cnt1 += s1[i]=='1',cnt2 += s2[i]=='1';}
	for(int i=1; i<=m; i++) {cnt3 += s3[i]=='1',cnt4 += s4[i]=='1';}
	llong tmp = 1ll;
	llong ret = 0ll;
	for(int i=1; i<=m; i++)
	{
		cur3 += s3[i]=='1'; cur4 += s4[i]=='1';
		if(s3[i]=='1' || s4[i]=='1')
		{
			if(s3[i]=='1' && s4[i]=='1') {tmp = tmp*2ll%P;}
			if(cnt2!=0) {ret = (ret+tmp*comb(cnt3+cnt2+cnt4-cur3-cur4-1,cnt2-1))%P;}
			else {ret = (ret+tmp*(cnt3+cnt4-cur3-cur4==0))%P;}
			if(cnt1!=0) {tmp = (tmp+comb(cur3+cur4+cnt1-1,cnt1-1))%P;}
			else {tmp = (tmp+(cur3+cur4==0))%P;}
		}
	}
	return ret;
}

int main()
{
	int n,m;
	fact[0] = 1ll;
	for(int i=1; i<=N*4; i++) fact[i] = fact[i-1]*i%P;
	finv[N*4] = quickpow(fact[N*4],P-2);
	for(int i=N*4-1; i>=0; i--) finv[i] = finv[i+1]*(i+1)%P;
	scanf("%d%d",&n,&m);
	scanf("%s%s%s%s",sa+1,sb+1,sc+1,sd+1);
	bool gg = false;
	for(int i=1; i<=n; i++) if(sa[i]=='1' || sb[i]=='1') gg = true;
	for(int i=1; i<=m; i++) if(sc[i]=='1' || sd[i]=='1') gg = true; 
	if(gg==false) {printf("1"); return 0;}
	llong ans = 0ll;
	ans += solve(n,m,sa,sb,sc,sd);
	ans += solve(m,n,sc,sd,sa,sb);
	ans %= P;
	printf("%lld\n",ans);
	return 0;
}