//
// Created by Ильдар Ялалов on 14.01.2020.
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")



#ifdef zxc

#include <random>
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <array>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <sstream>
#include <unordered_map>
#include <stack>

#else
#include <bits/stdc++.h>
#endif


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double dbl;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
typedef unsigned int uint;


#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


bool debug = 0;
const int MAXN = 2e5 + 100;
const int LOG = 20;
const int mod = 998244353;
const int MX = (1e7);
typedef long long li;

template<uint MD>
struct ModInt {
    using M = ModInt;
    uint v;

    ModInt() : v{0} {}

    ModInt(ll _v) : v{normS(_v % MD + MD)} {}

    explicit operator bool() const { return v != 0; }

    static uint normS(uint x) { return (x < MD) ? x : x - MD; };

    static M make(uint x) {
        M m;
        m.v = x;
        return m;
    }

    static M inv(const M &x) { return x.pow(MD - 2); }

    M operator+(const M &r) const { return make(normS(v + r.v)); }

    M operator-(const M &r) const { return make(normS(v + MD - r.v)); }

    M operator*(const M &r) const { return make(ull(v) * r.v % MD); }

    M operator/(const M &r) const { return *this * inv(r); }

    M &operator+=(const M &r) { return *this = *this + r; }

    M &operator-=(const M &r) { return *this = *this - r; }

    M &operator*=(const M &r) { return *this = *this * r; }

    M &operator/=(const M &r) { return *this = *this / r; }

    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
};

using Mint = ModInt<998244353>;

vector<int> g[MAXN];

Mint val[3][MAXN];

int used[MAXN];
int timer = 1;

int grandy[MAXN];

void solve() {
    int n;
    cin >> n;

    int mx_val = 0;
    for (int j = 0; j < 3; ++j) {
        int m;
        cin >> m;
        for (int i = 1; i <= n; ++i) {
            g[i].clear();
        }
        for (int i = 1; i <= m; ++i) {
            int a, b;
            cin >> a >> b;
            if (a > b)
                swap(a, b);
            g[a].pb(b);
        }

        Mint start = Mint((ll) 1e18);
        for (int i = n; i >= 1; --i) {
            timer++;
            for (int to:g[i]) {
                used[grandy[to]] = timer;
            }
            int top = 0;
            while (used[top] == timer) {
                top++;
            }
            grandy[i] = top;

            val[j][grandy[i]] += start.pow(i);

            mx_val = max(mx_val, top);
        }
    }

    Mint ans = 0;
    for (int i = 0; i <= mx_val; ++i) {
        for (int j = 0; j <= mx_val; ++j) {
            int last = i ^ j;
            if(last <= mx_val){
                ans += val[0][i] * val[1][j] * val[2][last];
            }

        }
    }
    cout << ans.v<<"\n";
}


signed main() {
#ifdef zxc
    freopen("../input.txt", "r", stdin);
//    freopen("../output.txt", "w", stdout);
#else
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(15);

    int t = 1;
    while (t--)
        solve();


    debug(1.0 * clock() / CLOCKS_PER_SEC);
}




Measured memory_bytes: 10368