#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=4e5+7;
const LL mod=998244353;
const LL inv2=499122177;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,m;
char s[5][N];
LL fac[N],ifac[N];
inline void Add(LL &x,LL y){x=x+y<mod?x+y:x+y-mod;}
inline LL qpow(LL a,LL b)
{
	LL ret=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ret=ret*a%mod;
	return ret;
}
inline void init(int n)
{
	fac[0]=ifac[0]=1;
	For(i,1,n)fac[i]=fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	rFor(i,n,1)ifac[i-1]=ifac[i]*i%mod;
}
inline LL C(int n,int k)
{
	if(n==k)return 1;
	return fac[n]*ifac[k]%mod*ifac[n-k]%mod;
}
inline LL Solve()
{
	int L=0,R=0,Sl=0,Sr=0;
	For(i,1,n)Sl+=s[1][i-1]-'0',Sr+=s[2][i-1]-'0';
	For(i,1,m)R+=s[3][i-1]-'0'+s[4][i-1]-'0';
	LL now=0,ans=0;
	For(i,1,m)
	{
		int type=s[3][i-1]-'0'+s[4][i-1]-'0';
		if(type)
		{
			Add(now,!Sl?(!L?1:0):C(Sl+L-1,L));
			L+=type,R-=type;
			type==2?Add(now,now):(void)1;
			Add(ans,now*(!Sr?(!R?1:0):C(Sr+R-1,R))%mod);
		}
	}
	return ans;
}
int main()
{
	file();
	read(n),read(m);
	init((n+m)*2);
	For(i,1,4)scanf("%s",s[i]);
	LL ans=0;
	Add(ans,Solve());
	swap(n,m);
	swap(s[1],s[3]);
	swap(s[2],s[4]);
	Add(ans,Solve());
	printf("%lld\n",ans==0?1:ans);
	return 0;
}
