#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<998244353>;
const int MX = 400000;
mint fac[MX],ifac[MX];
void precalc(){
	fac[0] = ifac[0] = 1;
	rep1(i,MX-1) fac[i] = fac[i-1]*i;
	rep1(i,MX-1) ifac[i] = ifac[i-1]/i;
}
mint C(int x,int y){
	if(x<y) return 0;
	if(x==y) return 1;
	if(y<0) return 0;
	return fac[x]*ifac[y]*ifac[x-y];
}

int H,W;
vector<bool> sh[2],sw[2];
void input(){
	cin>>H>>W;
	{
		string s;
		cin>>s;
		for(char c:s) sh[0].pb(c-'0');
	}
	{
		string s;
		cin>>s;
		for(char c:s) sh[1].pb(c-'0');
	}
	{
		vector<bool> b[2];
		rep(i,H){
			if(!sh[0][i] && !sh[1][i]) continue;
			b[0].pb(sh[0][i]);
			b[1].pb(sh[1][i]);
		}
		sh[0] = b[0], sh[1] = b[1];
		H = sh[0].size();
	}
	{
		string s;
		cin>>s;
		for(char c:s) sw[0].pb(c-'0');
	}
	{
		string s;
		cin>>s;
		for(char c:s) sw[1].pb(c-'0');
	}
	{
		vector<bool> b[2];
		rep(i,W){
			if(!sw[0][i] && !sw[1][i]) continue;
			b[0].pb(sw[0][i]);
			b[1].pb(sw[1][i]);
		}
		sw[0] = b[0], sw[1] = b[1];
		W = sw[0].size();
	}

}

const int MN = 100010;
mint fl[MN],fr[MN];
void calcfl(mint* fl,bool flipped){
	rep(i,MN) fl[i] = 0;
	int hnum = 0;
	rep(i,H) if(sh[flipped][i]) hnum++;
	if(hnum == 0){
		fl[0] = 1;
		return;
	}
	int wnum = 0;
	rep(l,W){
		fl[l] = C(hnum+wnum-1,wnum);
		rep(t,2) if(sw[t][l]) wnum++;
	}
}
mint calc(){
	if(W==0) return 0;
	calcfl(fl,0);
	rep(t,2) reverse(all(sw[t]));
	calcfl(fr,1);
	rep(t,2) reverse(all(sw[t]));
	reverse(fr,fr+W);
	mint res = 0;
	mint sum = 0;
	for(int l = W-1; l>=0; l--){
		sum += fr[l];
		if(sw[0][l] && sw[1][l]) sum*=2;
		res += fl[l] * sum;
	}
	// mint brute = 0;
	// rep(l,W) for(int r=l;r<W;r++){
	// 	mint tmp = fl[l]*fr[r];
	// 	for(int i=l;i<=r;i++) if(sw[0][i]&&sw[1][i]) tmp*=2;
	// 	brute += tmp;
	// }
	// assert(res == brute);
	return res;
}
int main(){
	precalc();
	input();
	if(H==0&&W==0){
		puts("1");
		return 0;
	}
	// H == 0 ?

	mint res = calc();

	swap(H,W);
	rep(t,2) swap(sh[t],sw[t]);

	res += calc();

	cout<<res<<endl;
}

Measured memory_bytes: 4468