#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int P = 998244353;
const int Q = 716070898;
const int limit = 1000;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, m, x[MAXN], y[MAXN], z[MAXN];
int bit[MAXN], f[MAXN], g[MAXN], res[MAXN];
vector <int> a[MAXN], b[MAXN], c[MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
void work(vector <int> *a, int *res) {
	static int vis[MAXN];
	for (int i = n; i >= 1; i--) {
		for (auto x : a[i]) if (x > i) vis[res[x]] = true;
		while (vis[res[i]]) res[i]++;
		for (auto x : a[i]) if (x > i) vis[res[x]] = false;
	}
}
int main() {
	read(n);
	read(m);
	for (int i = 1; i <= m; i++) {
		int x, y; read(x), read(y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	read(m);
	for (int i = 1; i <= m; i++) {
		int x, y; read(x), read(y);
		b[x].push_back(y);
		b[y].push_back(x);
	}
	read(m);
	for (int i = 1; i <= m; i++) {
		int x, y; read(x), read(y);
		c[x].push_back(y);
		c[y].push_back(x);
	}
	work(a, x);
	work(b, y);
	work(c, z);
	bit[0] = 1;
	for (int i = 1; i <= n; i++)
		bit[i] = 1ll * Q * bit[i - 1] % P;
	for (int i = 1; i <= n; i++) {
		update(f[y[i]], bit[i]);
		update(g[z[i]], bit[i]);
	}
	for (int i = 0; i <= limit; i++) {
		for (int j = 0; j <= limit; j++) {
			int k = i ^ j;
			update(res[i], 1ll * f[j] * g[k] % P);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		update(ans, 1ll * res[x[i]] * bit[i] % P);
	cout << ans << endl;
	return 0;
}
