#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}


const int LOG = 17;
const int N = 1 << LOG;
ll p[N + 3];
int n, m;
vector<int> g[N + 3];
vector<int> a[N + 3];
ll B[3][N];

int main()
{
	startTime = (double)clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	p[0] = 1;
	p[1] = bin_pow(10, 18);
	for (int i = 2; i < N; i++)
		p[i] = mult(p[i - 1], p[1]);

	scanf("%d", &n);
	for (int it = 0; it < 3; it++) {
		for (int i = 0; i <= n; i++) {
			g[i].clear();
			a[i].clear();
		}
		scanf("%d", &m);
		while(m--) {
			int v, u;
			scanf("%d%d", &v, &u);
			if (v < u) swap(v, u);
			g[v].push_back(u);
		}
		for (int i = n; i > 0; i--) {
			sort(a[i].begin(), a[i].end());
			int z = 0, pos = 0;
			while(true) {
				while(pos < (int)a[i].size() && a[i][pos] < z) pos++;
				if (pos == (int)a[i].size() || a[i][pos] > z) break;
				z++;
			}
			B[it][z] = add(B[it][z], p[i]);
			//B[it][z] = add(B[it][z], 1);
			//printf("%d ", z);
			for (int v : g[i])
				a[v].push_back(z);
		}
		//printf("\n");
	}

	for (int it = 0; it < 3; it++) {
		for (int k = 0; k < LOG; k++) {
			for (int mask = 0; mask < N; mask++) {
				if ((mask >> k) & 1) continue;
				ll x = B[it][mask], y = B[it][mask ^ (1 << k)];
				//B[it][mask] = sub(x, y);
				//B[it][mask ^ (1 << k)] = add(x, y);
				B[it][mask] = add(x, y);
				B[it][mask ^ (1 << k)] = sub(x, y);
			}
		}
	}
/*
	for (int it = 0; it < 3; it++) {
		for (int i = 0; i < N; i++)
			printf("%lld ", B[it][i]);
		printf("\n");
	}
*/
	for (int mask = 0; mask < N; mask++)
		for (int i = 1; i < 3; i++)
			B[0][mask] = mult(B[0][mask], B[i][mask]);

	for (int k = 0; k < LOG; k++) {
		for (int mask = 0; mask < N; mask++) {
			if ((mask >> k) & 1) continue;
			ll x = B[0][mask], y = B[0][mask ^ (1 << k)];
			//B[0][mask] = sub(x, y);
			//B[0][mask ^ (1 << k)] = add(x, y);
			B[0][mask] = add(x, y);
			B[0][mask ^ (1 << k)] = sub(x, y);
		}
	}
	ll ans = mult(B[0][0], rev(N));
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 15872