#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=100010;
const ll P=998244353,T=1000000000000000000%P;
int n,x,y,eg[3],m[3],hd[3][MAXN],nx[3][MAXN*2],ver[3][MAXN*2],mx[3],sg[3][MAXN],tmp[MAXN];
ll cnt[3][MAXN],ans;
ll qpow (ll a,ll b) {
	ll res=1;
	while (b) {
		if (b&1) {res=(res*a)%P;}
		a=(a*a)%P,b>>=1;
	}
	return res;
}
void add_edge (int t,int x,int y) {
	ver[t][++eg[t]]=y;
	nx[t][eg[t]]=hd[t][x];
	hd[t][x]=eg[t];
	return;
}
int main () {
	scanf("%d",&n);
	for (int i=0;i<=2;i++) {
		scanf("%d",&m[i]);
		for (int j=1;j<=m[i];j++) {
			scanf("%d%d",&x,&y);
			add_edge(i,min(x,y),max(x,y));
		}
		for (int j=n;j>=1;j--) {
			int cur=0;
			for (int k=hd[i][j];k;k=nx[i][k]) {
				tmp[sg[i][ver[i][k]]]++;
				while (tmp[cur]) {cur++;}
			}
			sg[i][j]=cur;
			for (int k=hd[i][j];k;k=nx[i][k]) {tmp[sg[i][ver[i][k]]]--;}
			cnt[i][cur]=(cnt[i][cur]+qpow(T,j))%P,mx[i]=max(mx[i],cur);
		}
	}
	for (int i=0;i<=mx[0];i++) {
		for (int j=0;j<=mx[1];j++) {
			ans=(ans+((cnt[0][i]*cnt[1][j])%P)*cnt[2][i^j])%P;
		}
	}
	printf("%lld\n",ans);
	return 0;
}