//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
           
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
           
//#define int long long
  
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
  
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("mincost.in", "r", stdin);
    //freopen("mincost.out", "w", stdout);
    #endif
}

const ll mod = 998244353;
const ll kek = 716070898;
const int K = 500;
const int MAXN = 1e5 + 100;
vector<int> g1[MAXN], g2[MAXN], g3[MAXN];
int v1[MAXN], v2[MAXN], v3[MAXN];
ll s1[K], s2[K], s3[K];
bool xy[K][K], xz[K][K], yz[K][K];

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

void relax1(int u) {
    bitset<K> bs;
    bs.reset();
    for (int to : g1[u]) {
        bs[v1[to]] = 1;
    }
    for (int i = 0; ; ++i) {
        if (!bs[i]) {
            v1[u] = i;
            break;
        }
    }
    s1[v1[u]] += binpow(kek, u + 1);
    if (s1[v1[u]] >= mod) {
        s1[v1[u]] -= mod;
    }
}

void relax2(int u) {
    bitset<K> bs;
    bs.reset();
    for (int to : g2[u]) {
        bs[v2[to]] = 1;
    }
    for (int i = 0; ; ++i) {
        if (!bs[i]) {
            v2[u] = i;
            break;
        }
    }
    s2[v2[u]] += binpow(kek, u + 1);
    if (s2[v2[u]] >= mod) {
        s2[v2[u]] -= mod;
    }
}

void relax3(int u) {
    bitset<K> bs;
    bs.reset();
    for (int to : g3[u]) {
        bs[v3[to]] = 1;
    }
    for (int i = 0; ; ++i) {
        if (!bs[i]) {
            v3[u] = i;
            break;
        }
    }
    s3[v3[u]] += binpow(kek, u + 1);
    if (s3[v3[u]] >= mod) {
        s3[v3[u]] -= mod;
    }
}

signed main() {
    FAST_IO();
    int n;
    cin >> n;
    int m1;
    cin >> m1;
    for (int i = 0; i < m1; ++i) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        if (u > v) {
            swap(u, v);
        }
        g1[u].push_back(v);
    }
    int m2;
    cin >> m2;
    for (int i = 0; i < m2; ++i) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        if (u > v) {
            swap(u, v);
        }
        g2[u].push_back(v);
    }
    int m3;
    cin >> m3;
    for (int i = 0; i < m3; ++i) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        if (u > v) {
            swap(u, v);
        }
        g3[u].push_back(v);
    }
    for (int i = n - 1; i >= 0; --i) {
        relax1(i);
        relax2(i);
        relax3(i);
    }
    ll ans = 0;
    for (int i = 0; i < K; ++i) {
        if (s1[i] == 0) {
            continue;
        }
        for (int j = 0; j < K; ++j) {
            if (s2[j] == 0) {
                continue;
            }
            for (int k = 0; k < K; ++k) {
                if (s3[k] == 0) {
                    continue;
                }
                int x = i, y = j, z = k;
                if (xy[x][y] || xz[x][z] || yz[y][z]) {
                    continue;
                }
                ll val = (s1[x] * s2[y]) % mod;
                val = (val * s3[z]) % mod;
                ans += val;
                if (ans >= mod) {
                    ans -= mod;
                }
                xy[x][y] = true;
                xz[x][z] = true;
                yz[y][z] = true;
            }
        }
    }
    cout << ans << '\n';
}  

Measured memory_bytes: 13952