// ---------- begin Scanner(require delimiter) ----------
mod scanner {
    use std;
    pub struct Scanner<R> {
        reader: R,
        buf: Vec<u8>,
    }
    #[allow(dead_code)]
    impl<R: std::io::BufRead> Scanner<R> {
        pub fn new(reader: R) -> Self {
            Scanner {
                reader: reader,
                buf: Vec::with_capacity(1024),
            }
        }
        fn read(&mut self, del: u8) {
            self.buf.clear();
            self.reader.read_until(del, &mut self.buf).ok();
            assert!(self.buf.pop().unwrap() == del);
        }
        pub fn next<T: std::str::FromStr>(&mut self, del: u8) -> T {
            self.read(del);
            std::str::from_utf8(&self.buf)
                .unwrap()
                .trim()
                .parse::<T>()
                .ok()
                .unwrap()
        }
        pub fn next_bytes(&mut self, del: u8) -> Vec<u8> {
            self.read(del);
            std::str::from_utf8(&self.buf)
                .unwrap()
                .trim()
                .bytes()
                .collect()
        }
    }
}
// ---------- end scanner(require delimiter) ----------
// ---------- begin ModInt ----------
const MOD: u32 = 998_244_353;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 {0} else {MOD - self.0})
    }
}

impl std::fmt::Display for ModInt {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl From<usize> for ModInt {
    fn from(val: usize) -> ModInt {
        ModInt((val % MOD as usize) as u32)
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------

// 解説読んだ
// 大きいやつから貪欲 -> まあ明らか
// これがGame DP と似てると気づく -> 不可能
// Grundy 数で解ける -> Game DP だとわかれば理解できるが...
fn run() {
    let stdin = std::io::stdin();
    let mut sc = scanner::Scanner::new(stdin.lock());
    let n: usize = sc.next(b'\n');
    let rad = ModInt((1_000_000_000_000_000_000u64 % MOD as u64) as u32);
    let mut pow = vec![ModInt::one(); n + 1];
    for i in 1..(n + 1) {
        pow[i] = pow[i - 1] * rad;
    }
    let mut memo = vec![];
    for _ in 0..3 {
        let m: usize = sc.next(b'\n');
        let mut deg = vec![0; n];
        let mut e = Vec::with_capacity(m);
        for _ in 0..m {
            let a = sc.next::<usize>(b' ') - 1;
            let b = sc.next::<usize>(b'\n') - 1;
            if a < b {
                deg[a] += 1;
                e.push((a, b));
            } else {
                deg[b] += 1;
                e.push((b, a));
            }
        }
        let mut g: Vec<_> = deg.into_iter().map(|d| Vec::with_capacity(d)).collect();
        for (a, b) in e {
            g[a].push(b);
        }
        let mut dp = vec![0; n];
        let mut elem = vec![false; n];
        for (v, g) in g.iter().enumerate().rev() {
            for &u in g.iter() {
                elem[dp[u]] = true;
            }
            dp[v] = elem.iter().position(|b| !*b).unwrap();
            for &u in g.iter() {
                elem[dp[u]] = false;
            }
        }
        let w = *dp.iter().max().unwrap();
        let mut sum = vec![ModInt::zero(); w + 1];
        for (dp, &p) in dp.into_iter().zip(pow.iter().skip(1)) {
            sum[dp] += p;
        }
        memo.push(sum);
    }
    let a = memo.pop().unwrap();
    let b = memo.pop().unwrap();
    let c = memo.pop().unwrap();
    let mut ans = ModInt::zero();
    for (i, &a) in a.iter().enumerate() {
        for (j, &b) in b.iter().enumerate() {
            ans += a * b * c.get(i ^ j).cloned().unwrap_or(ModInt::zero());
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 12540