#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3") 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 2e5;
const ll mod = 998244353;

ll n, m1, m2, m3, k;

inline ll step(ll a, ll x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return step(a, x - 1) * a % mod;
    }
    ll t = step(a, x / 2);
    return t * t % mod;
}

inline ll del(ll a, ll b) {
    return a * step(b, mod - 2) % mod;
}

vector <ll> A[maxn];
vector <ll> B[maxn];
vector <ll> C[maxn];

ll GA[maxn];
ll GB[maxn];
ll GC[maxn];

ll SA[maxn];
ll SB[maxn];
ll SC[maxn];

int main() {
    ll q, w, e, a, b, c, d, t;
    cin >> n;
    cin >> m1;
    for (q = 0; q < m1; q++) {
        cin >> a >> b;
        a--; b--;
        A[a].pb(b);
        A[b].pb(a);
    }
    cin >> m2;
    for (q = 0; q < m2; q++) {
        cin >> a >> b;
        a--; b--;
        B[a].pb(b);
        B[b].pb(a);
    }
    cin >> m3;
    for (q = 0; q < m3; q++) {
        cin >> a >> b;
        a--; b--;
        C[a].pb(b);
        C[b].pb(a);
    }
    ll osn = 1000000000;
    osn = osn * osn % mod;
    ll mx = 0;
    // GA[n - 1] = GB[n - 1] = GC[n - 1] = 0;
    for (q = n - 1; q >= 0; q--) {
        set <ll> S;
        for (auto v1 : A[q]) {
            if (v1 <= q) {
                continue;
            }
            S.insert(GA[v1]);
            // I.pb(GA[v1]);
        }
        for (w = 0; w <= n; w++) {
            if (S.find(w) == S.end()) {
                break;
            }
        }
        GA[q] = w;
        mx = max(GA[q], mx);
        SA[GA[q]] += step(osn, q + 1);
        SA[GA[q]] %= mod;
    }
    for (q = n - 1; q >= 0; q--) {
        set <ll> S;
        for (auto v1 : B[q]) {
            if (v1 <= q) {
                continue;
            }
            S.insert(GB[v1]);
            // I.pb(GA[v1]);
        }
        for (w = 0; w <= n; w++) {
            if (S.find(w) == S.end()) {
                break;
            }
        }
        GB[q] = w;
        mx = max(GB[q], mx);
        SB[GB[q]] += step(osn, q + 1);
        SB[GB[q]] %= mod;
    }
    for (q = n - 1; q >= 0; q--) {
        set <ll> S;
        for (auto v1 : C[q]) {
            if (v1 <= q) {
                continue;
            }
            S.insert(GC[v1]);
            // I.pb(GA[v1]);
        }
        for (w = 0; w <= n; w++) {
            if (S.find(w) == S.end()) {
                break;
            }
        }
        GC[q] = w;
        mx = max(GC[q], mx);
        SC[GC[q]] += step(osn, q + 1);
        SC[GC[q]] %= mod;
    }
    // ll suma = 0;
    ll ans = 0;
    for (q = 0; q <= mx; q++) {
        for (w = 0; w <= mx; w++) {
            ll x = q ^ w;
            ll dans = SA[q] * SB[w] % mod * SC[x] % mod;
            ans += dans;
            ans %= mod;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 32000