#include<iostream>
#include<cstdio>
using namespace std;
#define N 524289
#define mod 998244353
const int val=1000000000000000000%mod;
inline int M(int x){return (x>=mod)?(x-mod):x;}
inline int M1(int x){return (x<0)?(x+mod):x;}
inline int ksm(int p,int k){int res=1;while(k){if(k&1)res=1ll*res*p%mod;k>>=1;p=1ll*p*p%mod;}return res;}
int n,m,all,len,s[N],f[N],g[N],h[N],cnt=0;
struct Edge{int to,next;}e[N<<1];
inline void AddEdge(int x,int y){e[++cnt]=(Edge){y,h[x]};h[x]=cnt;}
inline void FWT(int f[],int len)
{
	int i,j,x,y;
	for(int j=1;j<len;j<<=1)
	for(int i=0;i<len;i++)if(i&j){x=f[i^j];y=f[i];f[i^j]=M(x+y);f[i]=M1(x-y);}
}
inline void IFWT(int f[],int len)
{
	int i,j,x,y,inv;
	for(int j=1;j<len;j<<=1)
	for(int i=0;i<len;i++)if(i&j){x=f[i^j];y=f[i];f[i^j]=M(x+y);f[i]=M1(x-y);}
	inv=ksm(len,mod-2);for(i=0;i<len;i++)f[i]=1ll*f[i]*inv%mod;
}
int tmp[N],P[N];
inline void solve()
{
	scanf("%d",&m);int i,x,y;
	for(i=1;i<=m;i++){scanf("%d%d",&x,&y);AddEdge(x,y);AddEdge(y,x);}
	s[n]=0;
	for(x=n-1;x>=1;x--)
	{
		for(i=h[x];i;i=e[i].next)if((y=e[i].to)>=x)tmp[s[y]]=1;
		s[x]=0;while(tmp[s[x]])++s[x];
		for(i=h[x];i;i=e[i].next)if((y=e[i].to)>=x)tmp[s[y]]=0;
	}
	for(i=1;i<=n;i++)f[s[i]]=M(f[s[i]]+P[i]);FWT(f,len);
	for(i=0;i<len;i++)g[i]=1ll*g[i]*f[i]%mod;
	for(i=1;i<=n;i++)s[i]=h[i]=0;cnt=0;
	for(i=0;i<len;i++)f[i]=0;
}
int main(){
	P[0]=1;for(int i=1;i<N;i++)P[i]=1ll*P[i-1]*val%mod;
	scanf("%d",&n);all=3*n;len=1;while(len<all)len<<=1;
	g[0]=1;FWT(g,len);solve();solve();solve();IFWT(g,len);printf("%d",g[0]);return 0;
}