#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr LL mod = 998244353;
constexpr int maxn = 100000;
int N, sg[maxn + 1], s[maxn + 1];
LL p[maxn + 1];
vector<int> G[maxn + 1];
vector<LL> g(){
    vector<LL> res;
    int M;
    cin >> M;
    for(int i = 1; i <= N; i += 1) G[i].clear();
    for(int i = 0, u, v; i < M; i += 1){
        cin >> u >> v;
        if(u > v) swap(u, v);
        G[u].push_back(v);
    }
    for(int i = N; i; i -= 1){
        sg[i] = 0;
        for(int v : G[i]) s[sg[v]] = 1;
        while(s[sg[i]]) sg[i] += 1;
        for(int v : G[i]) s[sg[v]] = 0;
        if(res.size() <= sg[i]) res.resize(sg[i] + 1);
        res[sg[i]] = (res[sg[i]] + p[i]) % mod;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> N;
    p[1] = 1000000000000000000LL % mod;
    for(int i = 2; i <= N; i += 1) p[i] = p[i - 1] * p[1] % mod;
    auto g1 = g();
    auto g2 = g();
    auto g3 = g();
    LL ans = 0;
    for(int i = 0; i < (int)g1.size(); i += 1)
        for(int j = 0; j < (int)g2.size(); j += 1){
            int k = i ^ j;
            if(k < (int)g3.size()) ans += g1[i] * g2[j] % mod * g3[k] % mod;
        }
    cout << ans % mod;
    return 0;
}
