#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define re register
#define LL long long
#define MOD 998244353
#define MAXN 300005
using namespace std;
LL n,ans,bs[3*MAXN];
LL rd(){
	LL x=0,tp=1;char c;c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x*10+c-'0');c=getchar();}
	return x*tp;
}
struct Graph{
	LL m,sg[MAXN],f[MAXN];
	vector<int>e[MAXN];
	void work(){
		int x,y;
		m=rd();
		for(int i=1;i<=m;i++){
			x=rd(),y=rd();
			if(x>y)swap(x,y);
			e[x].push_back(y);
		}
		for(int i=n;i>=1;i--){
			set<int>s;
			int sz=e[i].size();
			for(int j=0;j<sz;j++)s.insert(sg[e[i][j]]);
			while(s.count(sg[i]))sg[i]++;
			(f[sg[i]]+=bs[i])%=MOD;
			// printf("sg[%d]=%d\n",i,sg[i]);
		}
	}
}g[3];
int main(){
	// freopen("testdata.in","r",stdin);
	// freopen("shit.out","w",stdout);
	n=rd();int Sqr=sqrt(n);
	bs[0]=1;LL fuck=1000000000000000000ll%MOD;
	for(int i=1;i<=3*n;i++)bs[i]=bs[i-1]*fuck%MOD;
	for(int i=0;i<3;i++)g[i].work();
	for(int i=0;i<=500;i++)
		for(int j=0;j<=500;j++)
			(ans+=g[0].f[i]*g[1].f[j]%MOD*g[2].f[i^j]%MOD)%=MOD;
	printf("%lld\n",ans);
	// printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}