#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int, int> P;
typedef pair<P, int>PP;
const long long mod = 998244353;
vector<int>G[3][100005];
int G2[3][500];
int grundy[3][100005];
int n;

int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x & 1)res = res*a%mod;
		a = a*a%mod;
		x >>= 1;
	}
	return res;
}

signed main() {
	 cin >> n;

	 rep(i, 3) {
		 int m; cin >> m;
		 rep(j, m) {
			 int a, b; cin >> a >> b; a--; b--;
			 if (a > b)swap(a, b);
			 G[i][a].push_back(b);
		 }
		 rep(j, n)grundy[i][j] = -1;
		 for (int j = n - 1; j >= 0; j--) {
			 set<int>S;
			 for (int k : G[i][j])S.insert(grundy[i][k]);
			 int a = 0;
			 while (S.count(a))a++;
			 grundy[i][j] = a;
		 }
		 rep(j, n) {
			 G2[i][grundy[i][j]] += modpow(10, 18*(j + 1));
			 G2[i][grundy[i][j]] %= mod;
		 }
	 }

	int ans = 0;

	rep(i, 500) {
		rep(j, 500) {
			int k = i^j;
			ans += G2[0][i] * G2[1][j] %mod* G2[2][k]%mod;
			ans %= mod;
		}
	}

	cout << ans << endl;
}