#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////

vector<ll> grundy(vector<vector<ll>> g, ll N) {
	vector<ll> ret(N + 1, 0);

	vector<vector<ll>> s(N + 1);

	vector<ll> in(N + 1, 0);
	repn(v, N) {
		for (ll w : g[v]) { in[w]++; }
	}

	queue<ll> q;
	repn(v, N) {
		if (in[v] == 0) { ret[v] = 0; q.push(v); }
	}


	while (!q.empty()) {
		ll v = q.front();
		q.pop();

		for (ll w : g[v]) {
			s[w].push_back(ret[v]);
			in[w]--;

			if (in[w] == 0) {
				sort(s[w].begin(), s[w].end());

				for (ll i = 0; i < s[w].size(); i++) {
					if (ret[w] < s[w][i]) { break; }
					else if (ret[w] == s[w][i]) { ret[w]++; }
				}

				q.push(w);
			}
		}
	}

	return ret;

}


int main(){

	ll N;
	cin >> N;

	vector<vector<vector<ll>>> g(3, vector<vector<ll>>(N + 1));
	
	rep(i, 3) {
		ll M;
		cin >> M;

		repn(j, M) {
			ll a, b;
			cin >> a >> b;
			if (a < b) { swap(a, b); }
			g[i][a].push_back(b);
		}
	}

	vector<ll> gr[3];
	rep(i, 3) gr[i] = grundy(g[i], N);

	ll L=0;
	rep(i, 3)repn(j, N)L = max(L, gr[i][j]);

	vector<vector<mint>> s(3, vector<mint>(L + 1,0));

	rep(i, 3)repn(j, N) {
		//cout << gr[i][j] << endl;
		s[i][gr[i][j]] += (mint)10 ^ (18 * j);
	}

	
	mint ans = 0;

	rep(i, L + 1)rep(j, L + 1) {
		//cout << i << j << (i ^ j) << endl;

		if ((i^j) <= L) {
			ans += s[0][i] * s[1][j] * s[2][i^j];
		}
	}

	cout << ans;


	system("PAUSE");
}


Measured memory_bytes: 24900