// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

const int mod = 998244353;

int add(int a, int b) {
    return (a + b >= mod ? a + b - mod : a + b);
}

int sub(int a, int b) {
    return (a >= b ? a - b : mod + a - b);
}

int mult(int a, int b) {
    return (int64_t(a)* b) % mod;
}

int fpow(int a, int n, int r = 1) {
    while (n) {
        if (n % 2)
            r = mult(r, a);
        a = mult(a, a);
        n /= 2;
    }
    return r;
}

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();

    vector<vector<int>> X(n + 1), Y(n + 1), Z(n+ 1);

    for (int t = input<int>(); t != 0; --t) {
        int v, u;
        cin >> v >> u;
        X[min(v, u)].push_back(max(v, u));
    }
    
    for (int t = input<int>(); t != 0; --t) {
        int v, u;
        cin >> v >> u;
        Y[min(v, u)].push_back(max(v, u));
    }

    for (int t = input<int>(); t != 0; --t) {
        int v, u;
        cin >> v >> u;
        Z[min(v, u)].push_back(max(v, u));
    }

    vector<int> xrank(n + 1);
    for (int v = n; v >= 1; --v) {
        vector<char> ban(SZ(X[v]) + 1);

        for (int u: X[v])
            if (xrank[u] < SZ(ban))
                ban[xrank[u]] = 1;

        int it = 0;
        while (ban[it])
            ++it;

        xrank[v] = it;
    }

    vector<int> yrank(n + 1);
    for (int v = n; v >= 1; --v) {
        vector<char> ban(SZ(Y[v]) + 1);

        for (int u: Y[v])
            if (yrank[u] < SZ(ban))
                ban[yrank[u]] = 1;

        int it = 0;
        while (ban[it])
            ++it;

        yrank[v] = it;
    }

    vector<int> zrank(n + 1);
    for (int v = n; v >= 1; --v) {
        vector<char> ban(SZ(Z[v]) + 1);

        for (int u: Z[v])
            if (zrank[u] < SZ(ban))
                ban[zrank[u]] = 1;

        int it = 0;
        while (ban[it])
            ++it;

        zrank[v] = it;
    }
    
    auto BIG = fpow(10, 18);
    
    vector<int> x_by_rank(3 * n + 1);
    for (int v = 1; v <= n; ++v)
        x_by_rank[xrank[v]] = add(x_by_rank[xrank[v]], fpow(BIG, v));

    vector<int> A(1 << 18), B(1 << 18);
    for (int v = 1; v <= n; ++v)
        A[yrank[v]] = add(A[yrank[v]], fpow(BIG, v));

    for (int v = 1; v <= n; ++v)
        B[zrank[v]] = add(B[zrank[v]], fpow(BIG, v));

    for (int lvl = 0; lvl <= 17; ++lvl) {
        for (int off = 0; off < SZ(A); off += (2 << lvl)) {
            for (int i = 0; i < (1 << lvl); ++i) {
                int a = A[off + i];
                int b = A[off + (1 << lvl) + i];

                A[off + i] = add(a, b);
                A[off + (1 << lvl) + i] = sub(a, b);
            }
        }
    }

    for (int lvl = 0; lvl <= 17; ++lvl) {
        for (int off = 0; off < SZ(A); off += (2 << lvl)) {
            for (int i = 0; i < (1 << lvl); ++i) {
                int a = B[off + i];
                int b = B[off + (1 << lvl) + i];

                B[off + i] = add(a, b);
                B[off + (1 << lvl) + i] = sub(a, b);
            }
        }
    }

    for (int i = 0; i < SZ(A); ++i)
        A[i] = mult(A[i], B[i]);

    int d2 = fpow(2, mod - 2);
    for (int lvl = 17; lvl >= 0; --lvl) {
        for (int off = 0; off < SZ(A); off += (2 << lvl)) {
            for (int i = 0; i < (1 << lvl); ++i) {
                int a = A[off + i];
                int b = A[off + (1 << lvl) + i];

                A[off + i] = mult(add(a, b), d2);
                A[off + (1 << lvl) + i] = mult(sub(a, b), d2);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < SZ(A) and i < SZ(x_by_rank); ++i)
        ans = add(ans, mult(A[i], x_by_rank[i]));
    
    
    // int ans = 0;
    // for (int v = 1; v <= n; ++v)
    //     for (int u = 1; u <= n; ++u)
    //         ans = add(ans, mult(fpow(BIG, v + u), x_by_rank[yrank[v] xor zrank[u]]));

    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 17024