#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
#define RT 500
int n;
int m[3];
vi e[3][MN];
ll lol;
ll exps[MN];

bool tch[3][MN][RT];
ll sm[3][RT];

ll sym(int a, int b, int c){
    //cout << "doing " << a << " " << b << " " << c << "\n";
    int ree[3] = {a, b, c};
    ll ans = 0;
    do{
        ll pro = ((sm[0][ree[0]]*sm[1][ree[1]])%MOD*sm[2][ree[2]])%MOD;
        ans = (ans+pro)%MOD;
    } while(next_permutation(ree, ree+3));
    //cout << "adding " << ans << "\n";
    return ans;
}

int used[RT][RT];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    lol = 1000000000000000000LL % MOD;
    //lol = 3;
    exps[0] = 1;
    FOR(i, 1, MN-2){
        exps[i] = (exps[i-1]*lol)%MOD;
    }
    cin >> n;
    F0R(i, 3){
        cin >> m[i];
        F0R(_, m[i]){
            int u, v;
            cin >> u >> v;
            e[i][u].pb(v);
            e[i][v].pb(u);
        }
    }
    
    /*ll sm = 0;
    RFOR(i, n, 1){
        if(tch[i]){
            sm = (sm+exps[i])%MOD;
        } else{
            for(auto u : e[0][i]) if(u < i){
                tch[u] = true;
            }
        }
    }*/
    ll totsm = 0;
    FOR(i, 1, n) totsm = (totsm+exps[i])%MOD;

    int mx = 0;
    F0R(i, 3){
        //cout << "doing " << i << "\n";
        RFOR(cn, n, 1){
            F0R(j, RT){
                if(!tch[i][cn][j]){
                    //cout << cn << " on " << j << "\n";
                    mx = max(mx, j);
                    sm[i][j] = (sm[i][j]+exps[cn])%MOD;
                    for(auto nn : e[i][cn]) if(nn < cn){
                        tch[i][nn][j] = true;
                    }
                    break;
                }
            }
            /*if(tch[i][cn] == 3){
                //cout << cn << " bad\n";
                continue;
            } else if(tch[i][cn] == 2){
                //cout << cn << " ok\n";
                ot[i] += exps[cn];
                ot[i] %= MOD;
                for(auto nn : e[i][cn]) if(nn < cn){
                    if(tch[i][nn] % 2 == 0) tch[i][nn]++;
                }
            } else{
                //cout << cn << " good\n";
                sm[i] += exps[cn];
                sm[i] %= MOD;
                for(auto nn : e[i][cn]) if(nn < cn){
                    if(tch[i][nn] < 2) tch[i][nn] += 2;
                }
            }*/
        }
        //cout << sm[i] << " " << ot[i] << "\n";
    }

    ll ans = 0;
    FOR(i, 0, mx){
        FOR(j, i, mx){
            FOR(k, j, mx){
                if(!used[i][j] && !used[i][k] && !used[j][k]){
                    //cout << "using " << i << " " << j << " " << k << "\n";
                    ans += sym(i, j, k);
                    ans %= MOD;
                    used[i][j] = true;
                    used[i][k] = true;
                    used[j][k] = true;
                }
            }
        }
    }
    cout << ans << "\n";

    /*ll ans = ((sm[0]*sm[1])%MOD*sm[2])%MOD;
    ans += ((sm[0]*ot[1])%MOD*ot[2])%MOD;
    ans %= MOD;
    ans += ((ot[0]*sm[1])%MOD*ot[2])%MOD;
    ans %= MOD;
    ans += ((ot[0]*ot[1])%MOD*sm[2])%MOD;
    ans %= MOD;
    cout << ans << "\n";*/

    return 0;
}


Measured memory_bytes: 162944