#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<map>
#define RI register int
#define CI const int&
#define VI vector <int>:: iterator
using namespace std;
const int N=100005,mod=998244353,base=(long long)1e18%mod;
int n,x,y,ans,pw[N];
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
class Graph
{
	private:
		vector <int> v[N]; int m,sg[N];
		inline int SG(CI x)
		{
			if (~sg[x]) return sg[x]; map <int,bool> ext;
			for (VI to=v[x].begin();to!=v[x].end();++to) ext[SG(*to)]=1;
			while (ext[++sg[x]]); return sg[x];
		}
	public:
		int mx,c[N];
		inline void solve(void)
		{
			RI i; for (scanf("%d",&m),i=1;i<=m;++i)
			if (scanf("%d%d",&x,&y),x<y) v[x].push_back(y); else v[y].push_back(x);
			for (memset(sg,-1,sizeof(sg)),i=1;i<=n;++i) if (!~sg[i]) sg[i]=SG(i);
			for (i=1;i<=n;++i) mx=max(mx,sg[i]),inc(c[sg[i]],pw[i]);
		}
		inline void output(void)
		{
			RI i; printf("%d\n",mx);
			for (i=1;i<=n;++i) printf("%d ",sg[i]); putchar('\n');
			for (i=1;i<=n;++i) printf("%d ",c[i]); putchar('\n');
		}
}G[3];
int main()
{
	RI i,j; for (scanf("%d",&n),pw[0]=i=1;i<=n;++i) pw[i]=1LL*pw[i-1]*base%mod;
	for (i=0;i<3;++i) G[i].solve();
	for (i=0;i<=G[0].mx;++i) for (j=0;j<=G[1].mx;++j)
	inc(ans,1LL*G[0].c[i]*G[1].c[j]%mod*G[2].c[i^j]%mod);
	return printf("%d",ans),0;
}