#include<bits/stdc++.h>
#define pb push_back

typedef long long LL;

const int N=100005;
const int MOD=998244353;

int n,val[N],sg[3][N],s[3][N*2],tim[N],tmp[N*2];
std::vector<int> e[N];

int main()
{
	scanf("%d",&n);
	val[1]=1;
	for (int i=1;i<=18;i++) val[1]=(LL)val[1]*10%MOD;
	for (int i=2;i<=n;i++) val[i]=(LL)val[i-1]*val[1]%MOD;
	int mx[3]={0},now=0;
	for (int k=0;k<3;k++)
	{
		int m;scanf("%d",&m);
		for (int i=1;i<=m;i++)
		{
			int x,y;scanf("%d%d",&x,&y);
			e[x].pb(y);e[y].pb(x);
		}
		for (int i=n;i>=1;i--)
		{
			now++;
			for (int to:e[i]) if (to>i) tim[sg[k][to]]=now;
			for (sg[k][i]=0;tim[sg[k][i]]==now;sg[k][i]++);
			mx[k]=std::max(mx[k],sg[k][i]);
			e[i].clear();
		}
	}
	for (int k=0;k<3;k++)
		for (int i=1;i<=n;i++)
			(s[k][sg[k][i]]+=val[i])%=MOD;
	for (int i=0;i<=mx[0];i++)
		for (int j=0;j<=mx[1];j++)
			(tmp[i^j]+=(LL)s[0][i]*s[1][j]%MOD)%=MOD;
	int ans=0;
	for (int i=0;i<=mx[2];i++)
		(ans+=(LL)s[2][i]*tmp[i]%MOD)%=MOD;
	printf("%d\n",ans);
	return 0;
}