#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define P 998244353
#define M 300010
int F[M], IF[M];

void gcd(int a,int b,int &x,int &y) {
  if(b==0){x=1,y=0;return;}
  gcd(b,a%b,y,x),y-=a/b*x;
}
int inv(int n) {
  int x,y;gcd(n,P,x,y);
  if(x<0)x+=P;return x;
}
int C(int n, int k) {
	if (k < 0 || n < k) return 0;
	return (ll)F[n]*IF[k]%P*IF[n-k]%P;
}
int gg(int u, int v, int m) {
	if (u == 0 && v == 0 && m == 0) return 1;
	return C(u+v+m-1, m-1);
}

#define N 100010
int n, m;
string a, b, c, d;
int f[N], lu[N], lv[N];

int ff() {
	memset(f, 0, sizeof f);
	memset(lu, 0, sizeof lu);
	memset(lv, 0, sizeof lv);
	int le = 0;
	int ri = 0;
	for (int i = 0; i < m; i ++) {
		if (c[i] == '1') le ++;
		if (d[i] == '1') ri ++;
	}
	
	int u = 0, v = 0;
	//cout << n << " " << m << " " << a.length() << " " << b.length() << " " << c.length() << " " << d.length() << endl;
	//cout << le << " " << ri << endl;
	
	for (int i = 0; i < n; i ++) {
		int w = 0;
		if (a[i] == '1') w++;
		if (b[i] == '1') w++;
		f[i] = (ll)gg(u, v, le)*w%P;
		lu[i] = u;
		lv[i] = v;
		if (a[i] == '1') u++;
		if (b[i] == '1') v++;
	}
	
	for (int i = 0; i < n-1; i ++) {
		if (a[i+1] == '1' && b[i+1] == '1')
			(f[i+1] += (ll)f[i]*2%P) %= P;
		else
			(f[i+1] += f[i]) %= P;
	}
	
	int S = 0;
	u = v = 0;
	for (int i = n-1; i >= 0; i--) {
		int w = 0;
		if (a[i] == '1') w++;
		if (b[i] == '1') w++;
		if (w >= 1) S = (S + (ll)f[i]*gg(u, v, ri)%P)%P;
		if (a[i] == '1') u++;
		if (b[i] == '1') v++;
	}
	
	return S;
}

int main() {
	F[0]=1;for(int i=1;i<M;i++)F[i]=(ll)F[i-1]*i%P;
	IF[M-1]=inv(F[M-1]);for(int i=M-1;i;i--)IF[i-1]=(ll)IF[i]*i%P;
	cin >> n >> m;
	cin >> a >> b >> c >> d;
	if (a == string(n, '0') && a == string(n, '0') && c == string(m, '0') && d == string(m, '0')) {
		puts ("1");
		return 0;
	}
	int S = 0;
	S += ff();
	swap(a, c);
	swap(b, d);
	swap(n, m);
	(S += ff()) %= P;
	cout << S << endl;
	return 0;
}