// ${url}
//
#![allow(unused_imports)]
use std::io::*;
use std::io::Write;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! read_line {
    ($t:tt) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().parse::<$t>().unwrap()
        }
    }
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

// ===

struct Combination {
    fact: Vec<i64>,
    invfact: Vec<i64>,
}

impl Combination {
    fn inv(a: i64) -> i64 {
        Combination::pow(a, MOD - 2)
    }

    fn pow(a: i64, p: i64) -> i64 {
        let mut p = p;
        let mut aa = a;
        let mut ret = 1;
        while p >= 1 {
            if p & 1 == 1 {
                ret *= aa;
                ret %= MOD;
            }
            p >>= 1;
            aa = aa * aa % MOD;
        }
        ret
    }

    fn new(upto: usize) -> Self {
        let mut fact = vec![0; upto];
        let mut invfact = vec![0; upto];

        fact[0] = 1;
        for i in 1..upto {
            fact[i] = fact[i - 1] * (i as i64) % MOD;
        }

        invfact[upto - 1] = Combination::inv(fact[upto - 1]);
        invfact[0] = 1;
        for i in (1..upto - 1).rev() {
            invfact[i] = invfact[i + 1] * ((i + 1) as i64) % MOD;
        }

        Combination {
            fact: fact,
            invfact: invfact,
        }
    }

    fn comb(&self, n: usize, r: usize) -> i64 {
        if r < 0 || r > n {
            return 0;
        }
        self.fact[n] * self.invfact[r] % MOD * self.invfact[n - r] % MOD
    }
}

//===

const MOD: i64 = 998244353;

// fn solve2(comb: &Combination, h: usize, w: usize) -> i64 {
//     if w == 0 {
//         return 1;
//     }
//     comb.comb(h+w-1, h)
// }

// fn solve(comb: &Combination, h: usize, up: usize, dw: usize) -> i64 {
//     let mut ret = 0;
//     for i in 0..h {
//         for j in i..h {
//             ret += solve2(comb, i, up) * solve2(comb, h-1-j, dw);
//         }
//     }
//     debug!(ret, comb.comb(h+up+dw-1, up+dw));
//     ret
// }


// fn solve(h: usize, up: &Vec<usize>, dw: &Vec<usize>) {
// }


fn compute(a: Vec<char>, b: Vec<char>, c: Vec<char>, d: Vec<char>) -> i64 {
    let comb = Combination::new(310000);

    let left = a.into_iter().fold(0, |acc, x| acc+ifv!(x == '1', 1, 0));
    let right = b.into_iter().fold(0, |acc, x| acc+ifv!(x == '1', 1, 0));

    let up = c.into_iter().map(|c| ifv!(c == '1', 1, 0)).collect::<Vec<_>>();
    let dw = d.into_iter().map(|c| ifv!(c == '1', 1, 0)).collect::<Vec<_>>();
    let n = up.len();
    let mut dbl = vec![0; n];
    for i in 0..n {
        dbl[i] = (up[i] + dw[i]) as i64;
    }
    let mut up = (0..n).filter(|&i| dbl[i] >= 1).map(|i| up[i]).collect::<Vec<_>>();
    let mut dw = (0..n).filter(|&i| dbl[i] >= 1).map(|i| dw[i]).collect::<Vec<_>>();
    let dbl = dbl.into_iter().filter(|&d| d >= 1).collect::<Vec<_>>();
    let n = up.len();

    if n == 0 {
        return -1;
    }
    if left + right == 0 {
        let mut ret = 1;
        for i in 0..n {
            ret *= dbl[i];
            ret %= MOD;
        }
        return ret;
    }


    let solvel = |h: usize, up: &Vec<usize>, dw: &Vec<usize>| {
        let n = up.len();
        let mut ans = vec![];
        let mut u = 0;
        let mut d = 0;
        for i in 0..n {
            if h+u+d >= 1 {
                ans.push(comb.comb(h+u+d-1, u+d));
            } else {
                ans.push(1);
            }
            u += up[i];
            d += dw[i];
        }
        ans
    };

    let leftans = solvel(left, &up, &dw);
    up.reverse();
    dw.reverse();
    let mut rightans = solvel(right, &up, &dw);
    rightans.reverse();

    // debug!(left, right, leftans, rightans);

    for i in (1..n).rev() {
        rightans[i] *= dbl[i];
        rightans[i] %= MOD;
        rightans[i-1] += rightans[i];
        rightans[i-1] %= MOD;
    }
    rightans[0] *= dbl[0];
    rightans[0] %= MOD;

    let mut ans = 0;
    let inv2 = Combination::inv(2);
    for i in 0..n {
        if dbl[i] >= 1 {
            ans += leftans[i] * rightans[i];
            ans %= MOD;
        }
    }
    ans
}


fn main() {
    input! {
        n: usize, m: usize,
        a: chars,
        b: chars,
        c: chars,
        d: chars
    }

    let ans1 = compute(a.clone(), b.clone(), c.clone(), d.clone());
    let ans2 = compute(c, d, a, b);
    // debug!(ans1, ans2);
    if ans1 == -1 && ans2 == -1 {
        println!("1");
        return;
    }
    let ans1 = max(0, ans1);
    let ans2 = max(0, ans2);
    println!("{}", (ans1 + ans2) % MOD);
}


Measured memory_bytes: 14668