#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db long double
#define pii pair<int,ll>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
#define gc() getchar()
inline int rd()
{
	int x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')w=-1,c=gc();while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
const int N=100005,M=1<<19,P=998244353,iv2=(P+1)/2;
int n,s[N],sg[N],a[M],b[M],c[M],d[M];vi g[N];
inline int pw(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%P)if(b&1)r=1ll*r*a%P;return r;}
inline void fwt(int n,int*a,int o)
{
	for(int i=2;i<=n;i<<=1)for(int j=0;j<n;j+=i)rep0(k,0,(i>>1))
	{
		int x=a[j+k],y=a[j+k+(i>>1)];
		a[j+k]=(x+y)%P;a[j+k+(i>>1)]=(x+P-y)%P;
		if(o==-1)
		{
			a[j+k]=1ll*a[j+k]*iv2%P;
			a[j+k+(i>>1)]=1ll*a[j+k+(i>>1)]*iv2%P;
		}
	}
}
void calc(int n,int*a)
{
	int m=rd();rep(i,1,n)g[i].clear();
	rep(i,1,m){int u=rd(),v=rd();if(u>v)swap(u,v);g[u].pb(v);}
	per(i,n,1)
	{
		for(int x:g[i])s[sg[x]]++;
		sg[i]=0;while(s[sg[i]])sg[i]++;
		for(int x:g[i])s[sg[x]]--;
		a[sg[i]]=(a[sg[i]]+pw(10,18*i))%P;
	}
}
int main()
{
	n=rd();calc(n,a);calc(n,b);calc(n,c);
	fwt(M,a,1);fwt(M,b,1);fwt(M,c,1);
	rep0(i,0,M)d[i]=1ll*a[i]*b[i]%P*c[i]%P;
	fwt(M,d,-1);printf("%d\n",d[0]);return 0;
}