#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 998244353
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
inline int mul(int x , int y) { return (1LL*x*y)%MOD; }
int modpow(int x, int k) {
  int a = 1;
  while(k) {
    if (k&1)a=mul(a,x);
    x=mul(x,x);
    k>>=1;
  }
  return a;
}
int inv(int x) {
  return modpow(x,MOD-2);
}
int fact[400001];
int nCr(int n, int r) {
  if (r < 0 || r > n) return 0;
  return mul(mul(fact[n], inv(fact[r])),inv(fact[n-r]));
}

int f(int h, int u, int d) {
  if (u == 0 && d == 0) return 1;
  if (h == 0) return 0;
  return nCr(u+d+h-1, h-1);
}

int L[100000];
int R[100000];
int solve(int H, int W, string left, string right, string top, string bottom) {
  rep(i, W) L[i] = R[i] = 0;

  int h = 0, u = 0, d = 0;
  for (char c : right) h += c == '1';
  for (int r=W-1; r>=0; r--) if (top[r]=='1'||bottom[r]=='1') {
    R[r] = f(h, u, d);
    u += top[r]=='1';
    d += bottom[r]=='1';
  }

  h = 0, u = 0, d = 0;
  for (char c : left) h += c == '1';
  for (int l=0; l<W; l++) if (top[l]=='1' || bottom[l]=='1') {
    L[l] = f(h, u, d);
    u += top[l]=='1';
    d += bottom[l]=='1';
  }

  int s = 0, e = 0;
  for (int l=W-1; l>=0; l--) {
    add(e, R[l]);
    if (top[l]=='1'&&bottom[l]=='1') e = mul(2, e);
    add(s, mul(e, L[l]));
  }
  return s;
}

int N, M;
string A, B, C, D;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  fact[0] = 1;
  for (int i=1; i<=400000; i++) fact[i]=mul(fact[i-1],i);

  cin >> N >> M >> A >> B >> C >> D;
  int one = 0;
  for (char c : A) one += c == '1';
  for (char c : B) one += c == '1';
  for (char c : C) one += c == '1';
  for (char c : D) one += c == '1';
  if (one == 0) {
    cout << 1 << "\n";
    return 0;
  }

  int s = 0;
  add(s, solve(N, M, A, B, C, D));
  add(s, solve(M, N, C, D, B, A));
  cout << s << "\n";
  return 0;
}
