#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 100005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
	const int MOD = 998244353;
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
}
using namespace ModCalculator;
 
inline int ksm(int x, int k) {
    int ret = 1;
   	for (; k; k >>= 1) {
        if (k & 1) ret = Mul(ret, x);
        x = Mul(x, x);
    }
    return ret;
}

int n, tim, vis[MAXN], pw[MAXN];

struct Graph {
	vector<int> e[MAXN];
	int m, sg[MAXN], mxsg, sum[MAXN];
	
	void build() {
		read(m);
		for (int i = 1, u, v; i <= m; ++i) {
			read(u); read(v);
			e[min(u, v)].push_back(max(u, v));
		}
		for (int u = n; u >= 1; --u) {
			++tim;
			for (auto v : e[u]) {
				vis[sg[v]] = tim;
			}
			while (vis[sg[u]] == tim) {
				++sg[u];
			}
			Inc(sum[sg[u]], pw[u]);
			mxsg = max(mxsg, sg[u]);
		}
	}
} g1, g2, g3;

void init() {
	read(n);
	int p18 = ksm(10, 18);
	pw[0] = 1;
	for (int i = 1; i <= n; ++i) {
		pw[i] = Mul(pw[i - 1], p18);
	}
	g1.build();
	g2.build();
	g3.build();
}

void solve() {
	int ans = 0;
	for (int i = 0; i <= g1.mxsg; ++i) {
		for (int j = 0; j <= g2.mxsg; ++j) {
			Inc(ans, Mul(Mul(g1.sum[i], g2.sum[j]), g3.sum[i ^ j]));
		}
	}
	printf("%d\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}
