#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

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; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int Mod = 998244353, fft_g = 3;
const int inv2 = (Mod + 1) >> 1;

const int maxn = 262144;

inline int fpm(LL b, int e, const int &m)
{
	LL t = 1;
	for ( ; e; (b *= b) %= m, e >>= 1)
		if (e & 1) (t *= b) %= m;
	return t;
}

int N;
int w[maxn + 5];
int bitrev[maxn + 5];

inline void fft(int *a, const int &n)
{
	REP(i, 0, n) if (i < bitrev[i]) swap(a[i], a[bitrev[i]]);
	for (int i = 2, lyc = n >> 1; i <= n; i <<= 1, lyc >>= 1)
	{
		for (int j = 0; j < n; j += i)
		{
			int *l = a + j, *r = a + j + (i >> 1), *p = w;
			REP(k, 0, i >> 1)
			{
				int tmp = (LL)*r * *p % Mod;
				(*r = *l - tmp) %= Mod;
				(*l += tmp) %= Mod;
				++l, ++r;
				p += lyc;
			}
		}
	}
}

void fft_prepare(int num)
{
	int L = 0;
	for ( ; (1 << L) < num; ++L);
	N = 1 << L;
	REP(i, 0, N) bitrev[i] = bitrev[i >> 1] >> 1 | ((i & 1) << (L - 1));
	int step = fpm(fft_g, (Mod - 1) / N, Mod);
	w[0] = 1;
	REP(i, 0, N) w[i + 1] = (LL)w[i] * step % Mod;
}

const int max0 = 500100;

int fac[max0 + 5], ifac[max0 + 5];

inline void prepare()
{
	fac[0] = 1;
	REP(i, 0, max0) fac[i + 1] = (LL)fac[i] * (i + 1) % Mod;
	ifac[max0] = fpm(fac[max0], Mod - 2, Mod);
	for (int i = max0 - 1; i >= 0; --i) ifac[i] = (LL)ifac[i + 1] * (i + 1) % Mod;
}

int ans = 0;

inline void work(int n, int m, char *a, char *b, char *c, char *d)
{
	int tot = 1;
	REP(i, 0, n) if (a[i] == '1' && b[i] == '1') (tot <<= 1) %= Mod;
	int cnt = 0;
	REP(j, 0, m) cnt += c[j] == '1';
	int pre = 1;
	int prea = 0;
	int preb = 0;
	static int tmp0[maxn + 5], tmp1[maxn + 5];
	memset(tmp0, 0, sizeof tmp0);
	REP(i, 0, n) if (a[i] == '1' || b[i] == '1')
	{
		//x   (prea + x - 1, prea - 1) * (preb + cnt - x - 1, preb)
		//(prea + preb + cnt - 1, prea + preb)
		int tmp = 0;
		if (!(prea + preb)) tmp = 1;
		else if (!cnt) tmp = 0;
		else tmp = (LL)fac[prea + preb + cnt - 1] * ifac[prea + preb] % Mod * ifac[cnt - 1] % Mod;
		tmp = (LL)tmp * pre % Mod;
		(tmp0[i] += tmp) %= Mod;
		if (a[i] == '1' && b[i] == '1') pre = (LL)pre * inv2 % Mod;
		prea += a[i] == '1';
		preb += b[i] == '1';
	}
	memset(tmp1, 0, sizeof tmp1);
	cnt = 0;
	REP(j, 0, m) cnt += d[j] == '1';
	pre = 1;
	prea = preb = 0;
	for (int i = n - 1; i >= 0; --i) if (a[i] == '1' || b[i] == '1')
	{
		int tmp = 0;
		if (!(prea + preb)) tmp = 1;
		else if (!cnt) tmp = 0;
		else tmp = (LL)fac[prea + preb + cnt - 1] * ifac[prea + preb] % Mod * ifac[cnt - 1] % Mod;
		tmp = (LL)tmp * pre % Mod;
		(tmp1[n - i - 1] += tmp) %= Mod;
		if (a[i] == '1' && b[i] == '1') pre = (LL)pre * inv2 % Mod;
		prea += a[i] == '1';
		preb += b[i] == '1';
	}
	fft_prepare(n << 1);
	fft(tmp0, N);
	fft(tmp1, N);
	REP(i, 0, N) tmp0[i] = (LL)tmp0[i] * tmp1[i] % Mod;
	fft(tmp0, N);
	reverse(tmp0 + 1, tmp0 + N);
	int invN = fpm(N, Mod - 2, Mod);
	REP(i, 0, n) 
	{
		tmp0[i] = (LL)tmp0[i] * invN % Mod * tot % Mod;
		(ans += tmp0[i]) %= Mod;
	}
}

int n, m;
char a[maxn + 5], b[maxn + 5], c[maxn + 5], d[maxn + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	prepare();
	scanf("%d%d", &n, &m);
	bool tmp = 0;
	scanf("%s", a);
	scanf("%s", b);
	REP(i, 0, n) tmp |= a[i] == '1' || b[i] == '1';
	scanf("%s", c);
	scanf("%s", d);
	REP(i, 0, m) tmp |= c[i] == '1' || d[i] == '1';
	if (!tmp)
	{
		printf("1\n");
	}
	else
	{
		work(n, m, a, b, c, d);
		work(m, n, c, d, a, b);
		(ans += Mod) %= Mod;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 8704