//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=998244353;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
ll fac[500111],ifac[500111];
ll kissme(ll x,ll k){return k==0?1:kissme(x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,m;
char sa[100111],sb[100111],sc[100111],sd[100111];
ll pre[100111],suf[100111],pre2[100111];
ll C(ll x,ll y){return x<y?0:fac[x]*ifac[y]%mod*ifac[x-y]%mod;}
ll solve()
{
//	cerr<<"solve:"<<endl;
	int cntc=0;
	int cntd=0;
	for(int i=1;i<=m;i++)cntc+=sc[i]=='1';
	for(int i=1;i<=m;i++)cntd+=sd[i]=='1';
	int cnta=0,cntb=0;;
	pre[0]=1;
	for(int i=1;i<=n;i++)
	{
		cnta+=sa[i]=='1';
		cntb+=sb[i]=='1';
		if(cntc==0&&cnta==0&&cntb==0)pre[i]=1;
		else pre[i]=C(cntc+cnta+cntb-1,cnta+cntb)%mod;
	}
	cnta=cntb=0;
	suf[n+1]=1;
	for(int i=n;i>=1;i--)
	{
		cnta+=sa[i]=='1';
		cntb+=sb[i]=='1';
		if(cntd==0&&cnta==0&&cntb==0)suf[i]=1;
		else suf[i]=C(cntd+cnta+cntb-1,cnta+cntb)%mod;
	}
//	for(int i=0;i<=n+1;i++)cerr<<pre[i]<<" ";cerr<<endl;
//	for(int i=0;i<=n+1;i++)cerr<<suf[i]<<" ";cerr<<endl;
	
	ll ret=0;
	memset(pre2,0,sizeof(pre2));
	for(int i=1;i<=n;i++)
	{
		if(sa[i]-'0'+sb[i]-'0'==1)
		{
			pre2[i]=(pre[i-1]+pre2[i-1])%mod;
			ret+=pre2[i]*suf[i+1]%mod;
		}
		else if(sa[i]-'0'+sb[i]-'0'==2)
		{
			pre2[i]=(pre[i-1]+pre2[i-1])*2%mod;
			ret+=pre2[i]*suf[i+1]%mod;
		}
		else pre2[i]=pre2[i-1];
//		cerr<<pre2[i]<<" ";
	}
	return ret%mod;
}
int main()
{
	fac[0]=1;
	for(int i=1;i<=500005;i++)fac[i]=fac[i-1]*i%mod;
	ifac[500005]=kissme(fac[500005],mod-2);
	for(int i=500004;i>=0;i--)ifac[i]=ifac[i+1]*(i+1)%mod;
	scanf("%d%d",&n,&m);
	scanf("%s",sa+1);
	scanf("%s",sb+1);
	scanf("%s",sc+1);
	scanf("%s",sd+1);
	bool ok=0;
	for(int i=1;i<=n;i++)ok|=sa[i]=='1';
	for(int i=1;i<=n;i++)ok|=sb[i]=='1';
	for(int i=1;i<=m;i++)ok|=sc[i]=='1';
	for(int i=1;i<=m;i++)ok|=sd[i]=='1';
	
	ll ans=0;
	ans+=solve();
	swap(sa,sc);
	swap(sb,sd);
	swap(n,m);
	ans+=solve();
	if(!ok)ans++;
	cout<<ans%mod;
	return 0;
}

Measured memory_bytes: 10752