#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 998244353;
vector<int>pat[3][101010];
int gr[101010];
ll p10[555555];
vector<ll>calc(int t, int n)
{
	for (int i = n - 1; i >= 0; i--)
	{
		vector<int>f;
		f.resize(pat[t][i].size() + 3);
		for (int j = 0; j < pat[t][i].size(); j++)
		{
			int v = pat[t][i][j];
			if (gr[v] < f.size())f[gr[v]] = 1;
		}
		for (int j = 0; j < f.size(); j++)
		{
			if (f[j] == 0)
			{
				gr[i] = j;
				break;
			}
		}
	}
	vector<ll>r;
	r.resize(2000);
	for (int i = 0; i < n; i++)r[gr[i]] = (r[gr[i]] + p10[i + 1]) % mod;
	return r;
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < 3; i++)
	{
		int w;
		scanf("%d", &w);
		for (int j = 0; j < w; j++)
		{
			int za, zb;
			scanf("%d%d", &za, &zb);
			za--, zb--;
			if (za > zb)swap(za, zb);
			pat[i][za].push_back(zb);
		}
	}
	p10[0] = 1;
	for (int i = 0; i < 505050; i++)p10[i + 1] = p10[i] * (1000000000000000000LL % mod) % mod;
	//for (int i = 0; i < 505050; i++)p10[i + 1] = p10[i] * (10LL % mod) % mod;
	vector<ll>v[3];
	for (int i = 0; i < 3; i++)
	{
		vector<ll>z = calc(i, num);
		//for (int k = 0; k < z.size(); k++)printf("%lld ", z[k]); printf("\n");
		v[i] = z;
	}
	ll ans = 0;
	for (int i = 0; i < min(num, 1000); i++)
	{
		for (int j = 0; j < min(num, 1000); j++)
		{
			if ((i^j) < num)
			{
				//printf("%d %d %d\n", i, j, i^j);
				ans = (ans + v[0][i] * v[1][j] % mod*v[2][i^j]) % mod;
			}
		}
	}
	printf("%lld\n", ans);
}