#include<bits/stdc++.h>
#define PB push_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef vector<int>VI;
typedef long long LL;
const int N=100005,P=998244353,B=(LL)1e18%P;
int n,pw[N],m[3],sg[3][N],mx[3],f[3][N];VI G[N];bool ban[N];
int main(){
	scanf("%d",&n);
	pw[0]=1;rep(i,1,N-1)pw[i]=1LL*pw[i-1]*B%P;
	rep(i,0,2){
		scanf("%d",&m[i]);
		rep(j,1,n)G[j].clear();
		rep(j,1,m[i]){
			int k1,k2;scanf("%d%d",&k1,&k2);
			if(k2<k1)swap(k1,k2);
			G[k1].PB(k2);
		}
		per(k1,n,1){
			for(auto j:G[k1])ban[sg[i][j]]=1;
			int&k=sg[i][k1];
			while(ban[k])++k;
			for(auto j:G[k1])ban[sg[i][j]]=0;
		}
		rep(j,1,n){
			(f[i][sg[i][j]]+=pw[j])%=P;
			mx[i]=max(mx[i],sg[i][j]);
		}
	}
	int ans=0;
	rep(i,0,mx[0])rep(j,0,mx[1])(ans+=1LL*f[0][i]*f[1][j]%P*f[2][i^j]%P)%=P;
	printf("%d\n",ans);
	return 0;
}