#include<bits/stdc++.h>
using namespace std;

const int MOD = 998244353;
int poww(int a , int b){int tms = 1; while(b){if(b & 1) tms = 1ll * tms * a % MOD; a = 1ll * a * a % MOD; b >>= 1;} return tms;}
int mex[3][503] , N , M , ans; vector < int > nxt[100003];

void calc(int *arr){
	for(int i = 1 ; i <= N ; ++i) nxt[i].clear();
	cin >> M; for(int i = 1 ; i <= M ; ++i){int p , q; cin >> p >> q; nxt[min(p , q)].push_back(max(p , q));}
	static int tmp[503] , val[100003]; memset(val , 0 , sizeof(val));
	for(int i = N ; i ; --i){
		for(auto t : nxt[i]) tmp[val[t]] = 1;
		while(tmp[val[i]]) ++val[i];
		for(auto t : nxt[i]) tmp[val[t]] = 0;
		arr[val[i]] = (arr[val[i]] + poww(10 , 18 * i)) % MOD;
	}
}

int main(){
	cin >> N; calc(mex[0]); calc(mex[1]); calc(mex[2]);
	for(int i = 0 ; i <= 500 ; ++i)
		for(int j = 0 ; j <= 500 ; ++j)
			ans = (ans + 1ll * mex[0][i] * mex[1][j] % MOD * mex[2][i ^ j]) % MOD;
	cout << ans; return 0;
}
