#include <bits/stdc++.h>
using namespace std;

#define Fi first
#define Se second
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)
typedef tuple<int, int, int> t3;

int N;
int color[3][100010];
vector <int> E[3][100010];
const int mod = 998244353;

ll pw(ll x, ll y = mod - 2) {
	ll res = 1;
	while(y) {
		if(y & 1) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}

const int L = 1<<17;
void FFT_XOR(ll A[], int rev) {
	for(int len=1;len<L;len<<=1) {
		for(int i=0;i<L;i+=len*2) {
			for(int j=0;j<len;j++) {
				ll x = A[i+j];
				ll y = A[i+j+len];
				A[i+j] = (x + y) % mod;
				A[i+j+len] = (x - y + mod) % mod;
			}
		}
	}
	if(rev) rep(i, L) A[i] = A[i] * pw(L) % mod;
}

ll V[3][L];
ll rp[300010];

int main() {
	ll r = 1;
	rep(i, 18) r = r * 10 % mod;
	rp[0] = 1;
	for(int i=1;i<300010;i++) rp[i] = rp[i-1] * r % mod;
	scanf("%d", &N);
	rep(v, 3) {
		int m; scanf("%d", &m);
		while(m--) {
			int x, y;
			scanf("%d%d", &x, &y);
			E[v][x].pb(y);
			E[v][y].pb(x);
		}
		for(int i=N;i;i--) {
			set <int> x;
			for(int e : E[v][i]) if(e > i) x.insert(color[v][e]);
			for(int j=0;;j++) if(x.find(j) == x.end()) {
				color[v][i] = j;
				break;
			}
		}
		for(int i=1;i<=N;i++) {
			int c = color[v][i];
			V[v][c] = (V[v][c] + rp[i]) % mod;
		}
		FFT_XOR(V[v], 0);
	}
	rep(i, L) {
		V[0][i] = V[0][i] * V[1][i] % mod * V[2][i] % mod;
	}
	FFT_XOR(V[0], 1);

	printf("%lld\n", V[0][0]);
	return 0;
}