#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int Maxn = 100005;
const int mod = 998244353;
const int pw = 1000000;
const int Maxm = 1005;

int n;
vector <int> neigh[Maxn];
vector <int> my[3];
int col[3][Maxn];
int res;
bool was[3][Maxm][Maxm];

int toPower(int a, int p)
{
    int res = 1;
    while (p) {
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

void Solve(vector <int> &res, int col[])
{
    int m; scanf("%d", &m);
    for (int i = 1; i <= n; i++)
        neigh[i].clear();
    for (int i = 0; i < m; i++) {
        int a, b; scanf("%d %d", &a, &b);
        if (a > b) swap(a, b);
        neigh[a].push_back(b);
    }
    for (int i = n; i > 0; i--) {
        vector <int> seq;
        for (int j = 0; j < neigh[i].size(); j++)
            seq.push_back(col[neigh[i][j]]);
        sort(seq.begin(), seq.end());
        col[i] = 0;
        int my = toPower(pw, 3 * i);
        for (int j = 0; j < seq.size(); j++)
            if (seq[j] == col[i]) col[i]++;
        if (col[i] == res.size()) res.push_back(my);
        else res[col[i]] = (res[col[i]] + my) % mod;
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < 3; i++) {
        Solve(my[i], col[i]);
        assert(my[i].size() < Maxm);
    }
    for (int i = 0; i < my[0].size(); i++)
        for (int j = 0; j < my[1].size(); j++)
            for (int k = 0; k < my[2].size(); k++) {
                if (was[0][i][j] || was[1][i][k] || was[2][j][k]) continue;
                was[0][i][j] = was[1][i][k] = was[2][j][k] = true;
                res = (res + ll(my[0][i]) * my[1][j] % mod * my[2][k]) % mod;
            }
    printf("%d\n", res);
    return 0;
}
