#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define MSB(x) (31 - __builtin_clz(x))
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 19, maxS = 513, mod = 998244353;
const long long INF = 1000000000000000000ll;

template <class T1, class T2> inline void addMod(T1& a, T2 b)	{   a = (a + b) % mod;  }
template <class T1, class T2> inline void multMod(T1& a, T2 b)	{   a = a * b % mod;    }

long long pows[maxN], T[3][maxS];
vector <int> graph[3][maxN];
int mex[maxN], vis[maxN];
 
int main()
{
	int n;
	scanf ("%d", &n);
	pows[1] = INF % mod;
	FOR(i, 2, n+1)
		pows[i] = pows[i-1] * pows[1] % mod;
	FOR(s, 0, 3)
	{
		vector <int>* G = graph[s];
		int m;
		scanf ("%d", &m);
		while (m--)
		{
			int a, b;
			scanf ("%d%d", &a, &b);
			if (a > b)
				swap(a, b);
			G[a].pb(b);
		}
		
		FORD(v, n, 0)
		{
			for (int u : G[v])
				vis[mex[u]] = v;
			for (mex[v] = 0; vis[mex[v]] == v; mex[v]++) ;
			addMod(T[s][mex[v]], pows[v]);
		}
		
		fill(vis, vis+n+1, 0);
	}
	
	long long res = 0;
	FOR(a, 0, maxS) FOR(b, 0, maxS) FOR(c, 0, maxS) if ((a^b^c) == 0)
	{
		long long tak = T[0][a];
		multMod(tak, T[1][b]);
		multMod(tak, T[2][c]);
		addMod(res, tak);
	}
	
	printf("%lld\n", res);
	return 0;
}
