#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
using namespace std;
#define G getchar()
int read()
{
	int x=0; char ch=G;
	for (;!isdigit(ch);ch=G);
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return x;
}
#undef G
typedef long long ll;
const ll INF=1e18;
const int Mod=998244353;

int n,m; int p[100010];
struct Edge{
	int to,nxt;
}edge[100010];
int cnt,last[100010];
inline void addedge(int x,int y){
	if (x>y) swap(x,y);
	edge[++cnt]=(Edge){y,last[x]},last[x]=cnt;
}
int mxa=-1,mxb=-1,mxc=-1;
int a[100010],b[100010],c[100010];
bool mrk[100010]; int sg[100010];
int main()
{
	n=read();
	p[0]=1; p[1]=INF%Mod; for (int i=2;i<=n;i++) p[i]=1LL*p[i-1]*p[1]%Mod;
	
	m=read();
	cnt=0; memset(last+1,0,n*sizeof(int));
	for (int i=1;i<=m;i++) addedge(read(),read());
	for (int i=n;i;i--){
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=1;
		for (sg[i]=0;mrk[sg[i]];sg[i]++);
		a[sg[i]]=(a[sg[i]]+p[i])%Mod; mxa=max(mxa,sg[i]);
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=0;
	}
	
	m=read();
	cnt=0; memset(last+1,0,n*sizeof(int));
	for (int i=1;i<=m;i++) addedge(read(),read());
	for (int i=n;i;i--){
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=1;
		for (sg[i]=0;mrk[sg[i]];sg[i]++);
		b[sg[i]]=(b[sg[i]]+p[i])%Mod; mxb=max(mxb,sg[i]);
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=0;
	}
	
	m=read();
	cnt=0; memset(last+1,0,n*sizeof(int));
	for (int i=1;i<=m;i++) addedge(read(),read());
	for (int i=n;i;i--){
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=1;
		for (sg[i]=0;mrk[sg[i]];sg[i]++);
		c[sg[i]]=(c[sg[i]]+p[i])%Mod; mxc=max(mxc,sg[i]);
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=0;
	}
	
	int ans=0;
	for (int i=0;i<=mxa;i++)
		for (int j=0;j<=mxb;j++)
			if ((i^j)<=mxc)
				ans=(ans+1LL*a[i]*b[j]%Mod*c[i^j])%Mod;
	printf("%d\n",(ans+Mod)%Mod);
	return 0;
}