#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;

int n,m;
int a[100011][2],b[100011][2];
long long MOD=998244353;
long long fa[300011];
long long invfa[300011];
long long two[300011];


int p[100011];
int ppos[100011];
int q[100011];
int sp[100011];
int sa[100011][2];


//******************************
//返回d=gcd(a,b);和对应于等式ax+by=d中的x,y
long long extend_gcd(long long a,long long b,long long &x,long long &y)
{
 if(a==0&&b==0) return -1;//无最大公约数
 if(b==0){x=1;y=0;return a;}
 long long d=extend_gcd(b,a%b,y,x);
 y-=a/b*x;
 return d;
}
//*********求逆元素*******************
//ax = 1(mod n)
long long mod_reverse(long long a,long long n)
{
 long long x,y;
 long long d=extend_gcd(a,n,x,y);
 if(d==1) return (x%n+n)%n;
 else return -1;
}

long long inv(long long a)
{
    return mod_reverse(a,MOD);
}

/* 
long long exgcd(long long a,long long b,long long &x,long long &y)  
{  
    if(b==0)
    {  
        x=1;
        y=0;
        return a;
    }
    int r=exgcd(b,a%b,x,y);
    long long t=y;
    y=x-(a/b)*y;
    x=t;
    return r;
}  
long long inv(long long a)  
{  
    long long x,y;  
    long long r=exgcd(a,MOD,x,y);  
    if(r==1) return (x%MOD+MOD)%MOD;  
    return -1;  
}
*/

long long C(int n,int k)
{
    long long ans=fa[n]*invfa[k]%MOD*invfa[n-k]%MOD;
    return ans;
}


long long calc(long long x,long long y,long long z)
{
    if(x==0)
    {
        if(y==0 && z==0)return 1;
        return 0;
    }
    
    long long ans=(C(x+y+z,x)-C(x+y+z-1,x)+MOD)%MOD;
    
    
    //cout<<"calc"<<' '<<x<<' '<<y<<' '<<z<<"   "<<ans<<endl;
    
    return ans;
}

long long gao(int a[][2],int b[][2],int n,int m)
{
    int i,j,k;
    int mm1,mm2;
    mm1=mm2=0;
    for(i=1;i<=m;i++)
    {
        mm1+=(b[i][0]==1);
        mm2+=(b[i][1]==1);
        
        //cout<<b[i][0]<<' '<<b[i][1]<<endl;
    }
    
    
    
    long long ans=0;
    sa[0][0]=a[0][1]=0;
    for(i=1;i<=n;i++)
    {
        sa[i][0]=sa[i-1][0]+a[i][0];
        sa[i][1]=sa[i-1][1]+a[i][1];
    }
    
    int nn=0;
    for(i=1;i<=n;i++)
    {
        if(a[i][0]==1 && a[i][1]==1)
        {
            p[++nn]=2;
            ppos[nn]=i;
        }
        else if(a[i][0]==1 || a[i][1]==1)
        {
            p[++nn]=1;
            ppos[nn]=i;
        }
    }
    sp[0]=0;
    for(i=1;i<=nn;i++)
    {
        sp[i]=sp[i-1]+(p[i]==2);
    }
    
    
    long long tmp=0;
    long long lans=1;
    long long rans;
    int ll,rr;
    ll=1;
    
    
    //cout<<mm1<<' '<<mm2<<" mmm"<<endl;
    for(rr=1;rr<=nn;rr++)
    {
        rans=calc(mm2,sa[n][0]-sa[ppos[rr]][0],sa[n][1]-sa[ppos[rr]][1]);
        tmp=(tmp+lans*rans%MOD*two[sp[rr]-sp[ll-1]]%MOD)%MOD;
    }
    //cout<<"tmp0"<<tmp<<endl;
    
    ans=(ans+tmp)%MOD;
    for(ll=2;ll<=nn;ll++)
    {
        rans=calc(mm2,sa[n][0]-sa[ppos[ll-1]][0],sa[n][1]-sa[ppos[ll-1]][1]);
        tmp=(tmp-lans*rans%MOD*two[sp[ll-1]-sp[ll-2]]%MOD+MOD)%MOD;
        //cout<<tmp<<"  &&&"<<endl;
        tmp=tmp*inv(lans)%MOD;
        lans=calc(mm1,sa[ppos[ll]-1][0],sa[ppos[ll]-1][1]);
        tmp=tmp*lans%MOD;
        if(p[ll-1]==2)
        {
            tmp=tmp*inv(2)%MOD;
        }
        
        //cout<<"tmp"<<tmp<<endl;
        
        ans=(ans+tmp)%MOD;
    }
    
    
    return ans;
}


int main()
{
    int i,j,k;
    char c;
    fa[0]=1;
    invfa[0]=1;
    for(i=1;i<=300000;i++)
    {
        fa[i]=(fa[i-1]*i)%MOD;
        invfa[i]=inv(fa[i]);
    }
    two[0]=1;
    for(i=1;i<=300000;i++)
    {
        two[i]=(two[i-1]*2)%MOD;
    }
    
    bool f=0;
    scanf("%d %d",&n,&m);
    for(j=0;j<=1;j++)
    {
    for(i=1;i<=n;i++)
    {
        
            scanf(" %c",&c);
            a[i][j]=c-'0';
            if(a[i][j]==1)f=1;
    }
    }
    
    for(j=0;j<=1;j++)
    {
    for(i=1;i<=m;i++)
    {
            scanf(" %c",&c);
            b[i][j]=c-'0';
            if(b[i][j]==1)f=1;
    }
    }
    
    if(f==0)
    {
        cout<<1<<endl;
        return 0;
    }
    
    long long ans=0;
    ans+=gao(a,b,n,m);
    ans+=gao(b,a,m,n);
    ans%=MOD;
    cout<<(ans+MOD)%MOD<<endl;
    
    return 0;
} 


Measured memory_bytes: 10752