#include <algorithm>
#include <chrono>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>

using namespace std;

const int MOD = 998244353;

inline void ModMul(int& x, int y)
{
    x = (1LL * x * y) % MOD;
}

inline int GetModMul(int x, int y)
{
    ModMul(x, y);
    return x;
}

inline void ModSum(int& x, int y)
{
    x += y;
    if (x < 0) {
        x += MOD;
    }
    if (x >= MOD) {
        x -= MOD;
    }
}

inline int GetModSum(int x, int y)
{
    ModSum(x, y);
    return x;
}

const int MAX_N = 1e5;

int bases[MAX_N + 1];

void Prepare()
{
    bases[0] = 1;
    bases[1] = 1;
    for (int i = 0; i < 18; ++i) {
        ModMul(bases[1], 10);
    }
    for (int i = 2; i <= MAX_N; ++i) {
        bases[i] = GetModMul(bases[i - 1], bases[1]);
    }
}

int n;
vector<vector<int>> g[3];
vector<bool> used[3];
set<int> vs[3];

void MarkUsed(int index, int v)
{
    assert(!used[index][v]);
    used[index][v] = true;
    auto erased = vs[index].erase(v);
    assert(erased);
}

template <class TFunction>
void ForEachNeighbor(
    int index,
    int v,
    TFunction&& f)
{
    for (size_t i = 0; i < g[index][v].size(); ) {
        auto u = g[index][v][i];
        if (used[index][u]) {
            g[index][v][i] = g[index][v].back();
            g[index][v].pop_back();
            continue;
        }
        f(u);
        ++i;
    }
}

int GetSum(int index)
{
    unordered_set<int> forbidden;
    unordered_set<int> newUsed;
    for (auto it = vs[index].rbegin(); it != vs[index].rend(); ++it) {
        auto v = *it;
        if (forbidden.find(v) == forbidden.end()) {
            newUsed.insert(v);
            ForEachNeighbor(index, v, [&] (int u) {
                forbidden.insert(u);
            });
        }
    }
    assert(newUsed.size() > 0);
    int sum = 0;
    for (auto v : newUsed) {
        ModSum(sum, bases[v + 1]);
        MarkUsed(index, v);
    }
    return sum;
}

vector<int> GetSums(int index)
{
    vs[index].clear();
    used[index].assign(n, false);
    for (int j = 0; j < n; ++j) {
        vs[index].insert(j);
    }
    vector<int> result;
    while (vs[index].size() > 0) {
        result.push_back(GetSum(index));
    }
    return result;
}

void Solve()
{
    vector<int> sums[3];
    for (int i = 0; i < 3; ++i) {
        sums[i] = GetSums(i);
    }
    int result = 0;
    for (int i = 0; i < (int) sums[1].size(); ++i) {
        for (int j = 0; j < (int) sums[2].size(); ++j) {
            int k = i ^ j;
            if (k < (int) sums[0].size()) {
                ModSum(result, GetModMul(GetModMul(sums[1][i], sums[2][j]), sums[0][k]));
            }
        }
    }
    cout << result << endl;
}

bool Read()
{
    if (!(cin >> n)) {
        return false;
    }
    for (int i = 0; i < 3; ++i) {
        g[i].clear();
        g[i].resize(n);
        int m;
        cin >> m;
        for (int j = 0; j < m; ++j) {
            int a, b;
            cin >> a >> b;
            --a;
            --b;
            g[i][a].push_back(b);
            g[i][b].push_back(a);
        }
    }
    return true;
}

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    Prepare();

    while (Read()) {
        Solve();
    }

    return 0;
}


Measured memory_bytes: 24920