#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

ll modAdd(ll a, ll b) {
	return a+b >= MOD ? a+b-MOD : a+b;
}
ll modSub(ll a, ll b) {
	return a < b ? a-b+MOD : a-b;
}
ll modPow(ll a, ll b) {
	if (b & 1) return a * modPow(a, b-1) % MOD;
	if (b == 0) return 1;
	return modPow(a*a % MOD, b / 2);
}

// res[k] = \sum_{i,j : i^j == k} a[i] b[j]
// overflows if n res[i] overflows
void xorTF(vector<ll>& v) {
	for (int b = 1; b < v.size(); b *= 2) {
		for (int i = 0; i < v.size(); ++i) {
			if (i & b) continue;
			ll ri = v[i^b];
			v[i^b] = modSub(v[i], ri);
			v[i] = modAdd(v[i], ri);
		}
	}
}
vector<ll> xorConv(vector<ll> a, vector<ll> b) {
	xorTF(a); xorTF(b);
	for (int i = 0; i < a.size(); ++i) a[i] = (a[i] * b[i]) % MOD;
	xorTF(a);

	ll inv = modPow(a.size(), MOD-2);
	for (int i = 0; i < a.size(); ++i) a[i] = (a[i] * inv) % MOD;
	return a;
}

const int N = 1e5;
vector<int> conns[3][N];
int grundy[3][N];
vector<ll> vals[3];

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

	int n;
	cin >> n;

	for (int j = 0; j < 3; ++j) {
		int m;
		cin >> m;
		for (int i = 0; i < m; ++i) {
			int a, b;
			cin >> a >> b;
			--a; --b;
			conns[j][a].push_back(b);
			conns[j][b].push_back(a);
		}
		for (int i = n-1; i >= 0; --i) {
			vector<int> hits;
			for (auto t : conns[j][i]) {
				if (t > i) hits.push_back(grundy[j][t]);
			}
			sort(hits.begin(), hits.end());

			for (auto v : hits) {
				if (grundy[j][i] == v) ++grundy[j][i];
			}
		}
	}

	int h = 1;
	while(h < n) h <<= 1;
	for (int j = 0; j < 3; ++j) vals[j].resize(h, 0);

	ll base = modPow(10, 18);
	ll cur = base;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			vals[j][grundy[j][i]] = modAdd(vals[j][grundy[j][i]], cur);
		}
		cur = (cur * base) % MOD;
	}

	vector<ll> aux = xorConv(vals[0], xorConv(vals[1], vals[2]));
	cout << aux[0] << '\n';
}
