#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) x.begin(), x.end()
#define uniq(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

//random_device rd;
//mt19937_64 gen(rd());
//
//template<typename T>
//T rand(T l, T r) {
//    uniform_int_distribution<T> uid(l, r);
//    return uid(gen);
//}

const int maxn = 1e5 + 9;
vector<int> g[3][maxn];
int c[3][maxn];
int n;
int mod = 998244353;
int p[maxn];
vector<int> w[3];
int ans;
bool used[1000][1000];

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    p[0] = 1;
    p[1] = ((int)1e18) % mod;
    for (int i = 2; i < maxn; i++)
        p[i] = (p[i - 1] * p[1]) % mod;
    cin >> n;
    for (int j = 0; j < 3; j++)
    {
        int m;
        cin >> m;
        for (int i = 0; i < m; i++)
        {
            int a, b;
            cin >> a >> b;
            a--, b--;
            g[j][a].pb(b);
            g[j][b].pb(a);
        }
        int kek = 0;
        int t = 0;
        while (kek != n)
        {
            t++;
            for (int i = n - 1; i >= 0; i--)
            {
                if (c[j][i])
                    continue;
                bool fl = 0;
                for (int to : g[j][i])
                {
                    if (c[j][to] == t)
                        fl = 1;
                }
                if (!fl)
                {
                    c[j][i] = t;
                    if (w[j].size() < t + 1)
                        w[j].resize(t + 1, 0);
                    w[j][t] = (w[j][t] + p[i + 1]) % mod;
                    kek++;
                }
            }
        }
//        for (int i = 0; i < n; i++)
//            cout << c[j][i] << " ";
//        cout << "\n";
    }
    vector<vector<int> > q;
    for (int a = 0; a < 3; a++)
        for (int b = 0; b < 3; b++)
            for (int c = 0; c < 3; c++)
    {
        if (a != b && b != c && a != c)
        {
            vector<int> cur = {a, b, c};
            q.pb(cur);
        }
    }
    int sz = max(max(w[0].size(), w[1].size()), w[2].size());
    for (int a = 1; a < sz; a++)
    {
        for (int b = 1; b <= a; b++)
        {
            for (int c = 1; c <= b; c++)
            {
                if (used[a][b] || used[b][c] || used[a][c])
                    continue;

                bool fl = 0;
                for (auto u : q)
                {
                    vector<int> polina;
                    bool U[3] = {};
                    bool fll = 1;
                    for (int r = 0; r < 3; r++)
                    {
                        if (u[r] == 0)
                        {
                            polina.pb(a);
                            if (a == b && U[1])
                                fll = 0;
                            U[0] = 1;
                        }
                        else if (u[r] == 1)
                        {
                            polina.pb(b);
                            if (b == c && U[2])
                                fll = 0;
                            U[1] = 1;
                        }
                        else
                        {
                            polina.pb(c);
                            U[2] = 1;
                        }

                    }
                    if (!fll)
                        continue;
                    int cur = 1;

                    if ((int)w[0].size() > polina[0])
                        cur = (cur * w[0][polina[0]]) % mod;
                    else
                        fll = 0;

                    if ((int)w[1].size() > polina[1])
                        cur = (cur * w[1][polina[1]]) % mod;
                    else
                        fll = 0;

                    if ((int)w[2].size() > polina[2])
                        cur = (cur * w[2][polina[2]]) % mod;
                    else
                        fll = 0;

                    if (fll)
                    {
                        ans = (ans + cur) % mod;
                        fl = 1;
                    }
                }
                if (fl)
                {
                    used[a][b] = 1;
                    used[a][c] = 1;
                    used[b][c] = 1;
                }
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 20736