#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MOD = 998244353;

const double EPS = 1e-6;
const int MAX = 300 * 1000 + 47;


int F[MAX];
int RF[MAX];
char S[4][MAX];
int U[MAX], D[MAX], L[MAX], R[MAX];
int X[2][MAX];

int BP(int a, int n)
{
    int res = 1;
    while(n)
    {
        if (n & 1)res = (res * 1LL * a) % MOD;
        a = (a * 1LL * a) % MOD;
        n >>= 1;
    }
    return res;
}

int BIN(int n, int k)
{
    if (k > n)return 0;
    return (F[n] * 1LL * RF[k] % MOD) * 1LL * RF[n-k] % MOD;
}


void calc(int *A, int *B, int *C, int n, int m, int *R)
{
    int x = 0, y = 0;
    FOR(i, 0, n) x += A[i];
    FOR(i, 0, m)
    {
        y += B[i] + C[i];
        R[i] = BIN(x + y - 1, x - 1);
    }
}

int SOLVE(int *U, int *D, int *L, int *R, int n, int m)
{
    calc(U, L, R, n, m, X[0]);
    reverse(L, L + m);
    reverse(R, R + m);
    calc(D, L, R, n, m, X[1]);
    reverse(L, L + m);
    reverse(R, R + m);
    reverse(X[1], X[1] + m);
    X[1][m] = 1;
    int ans = 0;
    int sum = 0;
    
    
    FOR(i, 0, m)
    {
        sum += i ? X[0][i-1] : 1;
        if (sum >= MOD)sum -= MOD;
        sum *= L[i] + R[i];
        if (sum >= MOD)sum -= MOD;
        ans = (ans + sum * 1LL * X[1][i+1]) % MOD;
    }
    return ans;
}


int main()
{
    F[0] = RF[0] = 1;
    FOR(i, 1, MAX)
    {
        F[i] = F[i-1] * 1LL * i % MOD;
        RF[i] = BP(F[i], MOD - 2);
    }
    
    int n, m;
    scanf("%d%d", &n, &m);
    
    FOR(i, 0, 4)
        scanf("%s", S[i]);
    
    int sz = 0;
    FOR(i, 0, n)
        if (S[0][i] != '0' || S[1][i] != '0')
            L[sz] = S[0][i] - '0',
            R[sz] = S[1][i] - '0',
            ++sz;
    n = sz;
    sz = 0;
    FOR(i, 0, m)
        if (S[2][i] != '0' || S[3][i] != '0')
            U[sz] = S[2][i] - '0',
            D[sz] = S[3][i] - '0',
            ++sz;
    m = sz;

    
    int res = SOLVE(U, D, L, R, m, n);
    res += SOLVE(L, R, U, D, n, m);
    res %= MOD;
    cout << max(1, res) << endl;
    
    return 0;
}
