#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define rer(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> ppi;
typedef vector<ll> vi;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest) { 
	cout << arg << " "; Debug(rest...); }
template<class T>ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<< ", ";out<<v.back();}out << "]";return out;}
template<class S, class T>ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";return out;}
const int MAX_N = 600100;
const double eps = 1e-6;
const ll mod = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll fac[MAX_N], inv[MAX_N], fiv[MAX_N]; //fiv:inv(fac(i))
ll pow2[MAX_N];

/*
ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}

ll invf(ll a) {
	return mod_pow(a, mod - 2);
}
*/

void C_init(int n) {
	fac[0] = fac[1] = 1; inv[1] = 1;
	fiv[0] = fiv[1] = 1;
	pow2[0] = 1; pow2[1] = 2;
	rep(i, 2, n + 1) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fiv[i] = fiv[i - 1] * inv[i] % mod;
		pow2[i] = pow2[i - 1] * 2 % mod;
	}
}

ll getC(int a, int b) { //assume a >= b
	if(a < b || a < 0 || b < 0) return 0;
	return fac[a] * fiv[b] % mod * fiv[a - b] % mod;
}

int N, M;
string A, B, C, D;
ll bitcnt[MAX_N];
ll sum[MAX_N];

ll solve2(int y, int z, int x) {
	if(x == 0) {
		if(y == 0 && z == 0) return 1;
		else return 0;
	}
	else return getC(x + y + z - 1, x - 1);
}

ll solve_sub() {
	int ccnt = accumulate(all(C), 0) - '0' * M;
	int dcnt = accumulate(all(D), 0) - '0' * M;
	int acnt = 0, bcnt = 0;
	bitcnt[0] = 0;
	rep(i, 0, N) bitcnt[i + 1] = bitcnt[i] + ((A[i] == '1' && B[i] == '1') ? 1 : 0);
	//debug(vi(bitcnt, bitcnt + N + 1));
	sum[N] = 0;
	rer(i, N, 0) {
		if(A[i] == '0' && B[i] == '0') sum[i] = sum[i + 1];
		else {
			sum[i] = sum[i + 1] + solve2(acnt, bcnt, dcnt) * pow2[bitcnt[i + 1]] % mod;
			sum[i] %= mod;
		}
		if(A[i] == '1') acnt++;
		if(B[i] == '1') bcnt++;
	}
	acnt = 0; bcnt = 0;
	//debug(vi(sum, sum + N + 1));
	acnt = 0; bcnt = 0;
	ll res = 0;
	ll mul = 1;
	rep(i, 0, N) {
		if(A[i] == '0' && B[i] == '0') continue;
		ll a = solve2(acnt, bcnt, ccnt);
		ADD(res, a * mul % mod * sum[i] % mod);
		if(A[i] == '1') acnt++;
		if(B[i] == '1') bcnt++;
		if(A[i] == '1' && B[i] == '1') MUL(mul, inv[2]);
	}
	return res;
}



void solve() {
	C_init(600010);
	cin >> N >> M;
	cin >> A >> B >> C >> D;
	int a = accumulate(all(A), 0) - '0' * N;
	int b = accumulate(all(B), 0) - '0' * N;
	int c = accumulate(all(C), 0) - '0' * M;
	int d = accumulate(all(D), 0) - '0' * M;
	if(a == 0 && b == 0 && c == 0 && d == 0) {
		cout << 1 << "\n";
		return;
	}
	ll ans = 0;
	if(a != 0 || b != 0) ADD(ans, solve_sub());
	if(c != 0 || d != 0) {
		swap(N, M);
		swap(A, C);
		swap(B, D);
		ADD(ans, solve_sub());
	}
	cout << ans << "\n";
}


int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(5);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 23632