#include<cstdio>
#include<algorithm>
#define N_ 301000
using namespace std;
int n, m;
char X1[N_], X2[N_], Y1[N_], Y2[N_];
long long U[N_], D[N_], L[N_], R[N_], F[N_], InvF[N_], UU[N_], LL[N_], res;
long long Mod = 998244353;
long long Pow(long long a, int b){
    long long r = 1;
    while(b){
        if(b&1)r=r*a%Mod;
        a=a*a%Mod;b>>=1;
    }
    return r;
}
long long Comb(int a, int b){
    if(a<b)return 0;
    return F[a] * InvF[b]%Mod*InvF[a-b]%Mod;
}
long long Calc(int a, int b, int c){
    return (Comb(a+b+c,c) - Comb(a+b+c-1, c) + Mod) % Mod;
}
int main(){
    int i;
    scanf("%d%d",&n,&m);
    scanf("%s",X1+1);
    scanf("%s",X2+1);
    scanf("%s",Y1+1);
    scanf("%s",Y2+1);
    F[0]=1;
    int sum = 0;
    for(i=1;i<=n;i++){
        sum += X1[i]-'0';
        sum += X2[i]-'0';
    }
    for(i=1;i<=m;i++){
        sum += Y1[i]-'0';
        sum += Y2[i]-'0';
    }
    if(!sum){
        printf("1\n");
        return 0;
    }
    for(i=1;i<=300000;i++)F[i]=F[i-1]*i%Mod;
    InvF[300000] = Pow(F[300000], Mod-2);
    for(i=300000;i>=1;i--)InvF[i-1] = InvF[i] * i % Mod;
    int s1 = 0, s2 = 0, cc = 0;
    for(i=1;i<=m;i++)if(Y1[i] == '1')cc++;
    U[0] = 1;
    for(i=1;i<=n;i++){
        if(X1[i] == '1')s1++;
        if(X2[i] == '1')s2++;
        U[i] = Calc(s1,s2,cc);
    }
    s1 = s2 = cc = 0;
    for(i=1;i<=m;i++)if(Y2[i] == '1')cc++;
    D[n+1] = 1;
    for(i=n;i>=1;i--){
        if(X1[i] == '1')s1++;
        if(X2[i] == '1')s2++;
        D[i] = Calc(s1,s2,cc);
    }
    s1 = s2 = cc = 0;
    for(i=1;i<=n;i++)if(X1[i] == '1')cc++;
    L[0] = 1;
    for(i=1;i<=m;i++){
        if(Y1[i] == '1')s1++;
        if(Y2[i] == '1')s2++;
        L[i] = Calc(s1,s2,cc);
    }
    s1 = s2 = cc = 0;
    R[m+1] = 1;
    for(i=1;i<=n;i++)if(X2[i] == '1')cc++;
    for(i=m;i>=1;i--){
        if(Y1[i] == '1')s1++;
        if(Y2[i] == '1')s2++;
        R[i] = Calc(s1,s2,cc);
    }
    UU[0] = 1;
    for(i=1;i<=n;i++){
        int t = X1[i]-'0' + X2[i]-'0';
        UU[i] = UU[i-1];
        if(t==2) UU[i] += UU[i-1];
        if(t) UU[i] += U[i];
        UU[i]%=Mod;
    }
    LL[0] = 1;
    for(i=1;i<=m;i++){
        int t = Y1[i]-'0' + Y2[i]-'0';
        LL[i] = LL[i-1];
        if(t==2) LL[i] += LL[i-1];
        if(t) LL[i] += L[i];
        LL[i]%=Mod;
    }
    for(i=1;i<=n;i++){
        int c = X1[i] - '0' + X2[i] - '0';
        res = (res + UU[i-1]*D[i+1]*c) % Mod;
    }
 //   printf("%lld\n",res);
    for(i=1;i<=m;i++){
        int c = Y1[i] - '0' + Y2[i] - '0';
        res = (res + LL[i-1]*R[i+1]*c) % Mod;
    }
    for(i=1;i<=4;i++){
//        printf("%lld %lld %lld %lld %lld %lld\n",U[i],D[i],L[i],R[i],UU[i],LL[i]);
    }
    printf("%lld\n",res);
}