#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl


using namespace std;

#ifdef LOCAL
static struct __timestamper {
    string what;
    __timestamper(const char* what) : what(what){};
    __timestamper(const string& what) : what(what){};
    ~__timestamper(){
        TIMESTAMPf("%s", what.data());
    }
} __TIMESTAMPER("end");
#else
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;


constexpr int MOD = 998244353;
void add(int &x, int y) {
    x += y;
    if (x >= MOD) x -= MOD;
}
int mul(int x, int y) {
    return 1LL * x * y % MOD;
}
int bin(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}
int inv(int x) {
    return bin(x, MOD - 2);
}

int solve(int n, vector<vector<pair<int, int>>> ced) {
    vector<int> cur(2);
    cur[1] = 1;

//    int pw = 1;
    int pw = bin(10, 18);


    vector<vector<int>> mex(3, vector<int>(n*2));
    vector<vector<int>> sum_mex(3, vector<int>(n*2));

    for (int i = 0; i < 3; i++) {
        vector<vector<int>> e(n);
        for (auto o : ced[i]) {
            e[o.first].push_back(o.second);
        }

        for (int v = n - 1; v >= 0; v--){
            vector<int> vv;
            for (int to : e[v]) {
                vv.push_back(mex[i][to]);
            }
            sort(vv.begin(), vv.end());
            while (binary_search(vv.begin(), vv.end(), mex[i][v])) mex[i][v]++;
            add(sum_mex[i][mex[i][v]], bin(pw, v + 1));
        }
    }
//    for (auto v : mex) {
//        dbv(v);
//    }
//    exit(0);

//    int ans = 0;
//    for (int i = 0; i < n; i++) {
//        int prod = 1;
//        for (int j = 0; j < 3; j++) prod =mul(prod, sum_mex[j][i]);
//        add(ans, prod);
//    }
//    return ans;

//    vector<int> prod(n);
//    for (int i = 0; i < n; i++) prod[i] = mul(sum_mex[0][i], sum_mex[1][i]);

//    int ans = 0;
//    for (int k = 0; k < n; k++) {
//        if (k % 1000 == 0) db(k);
//        for (int j = 0; j < n; j++) {
//            add(ans, mul(sum_mex[2][k], mul(sum_mex[1][j], sum_mex[0][j ^ k])));
//        }
//    }

    int N = 1;
    while (N < n) N <<= 1;

    auto xft = [&](vector<int> &a) {
        for (int k = 1; k < N; k <<= 1) {
            for (int i = 0; i < N; i += 2 * k) {
                for (int j = 0; j < k; j++) {
                    int u = a[i + j], v = a[i + k + j];
                    a[i + j] = (u + v) % MOD;
                    a[i + k + j] = (u - v + MOD) % MOD;
                }
            }
        }
    };
    sum_mex[1].resize(N);
    sum_mex[2].resize(N);
    xft(sum_mex[1]);
    xft(sum_mex[2]);
    for (int i = 0; i < N; i++) sum_mex[1][i] = mul(sum_mex[1][i], sum_mex[2][i]);
    xft(sum_mex[1]);
    int oN = inv(N);
    for (int i = 0; i < N; i++) sum_mex[1][i] = mul(sum_mex[1][i], oN);

    int ans = 0;
    for (int i =0; i < n; i++) {
        add(ans, mul(sum_mex[0][i], sum_mex[1][i]));
    }


    return ans;
}

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif

    int n;
    while (scanf("%d", &n) == 1) {
        vector<vector<pair<int, int>>> ed(3);
        for (int i = 0; i < 3; i++) {
            int m;
            scanf("%d", &m);
            ed[i].resize(m);
            for (int j = 0; j < m; j++) {
                scanf("%d%d", &ed[i][j].first, &ed[i][j].second);
                ed[i][j].first--;
                ed[i][j].second--;
                if (ed[i][j].first > ed[i][j].second) swap(ed[i][j].first, ed[i][j].second);
            }
        }

        printf("%d\n", solve(n, ed));
    }

    return 0;
}


Measured memory_bytes: 13808