// Created by Nikolay Budin

#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
#ifdef LOCAL
	mt19937 tw(9450189);
#else
	mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }

const int MOD = 998244353;

void add(int& a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int sum(int a, int b) {
	add(a, b);
	return a;
}

int mult(int a, int b) {
	return (ll) a * b % MOD;
}

int mpow(int a, int b) {
	int ret = 1;
	while (b) {
		if (b & 1) {
			ret = mult(ret, a);
		}
		a = mult(a, a);
		b /= 2;
	}
	return ret;
}

int inv(int n) {
	return mpow(n, MOD - 2);
}

void transform(vector<int>::iterator from, vector<int>::iterator to) { 
    if (to - from == 1) 
        return;
    auto mid = from + (to - from) / 2; 
    transform(from, mid); 
    transform(mid, to); 
    for(int i = 0; i < mid - from; i++) {
        int a = *(from + i);
        int b = *(mid + i);
        *(from + i) = sum(a, b);
        *(mid + i) = sum(a, MOD - b);
    }
} 

void solve() {
	int n;
	cin >> n;
	int bpv = 1;
	while (bpv < n) {
		bpv *= 2;
	}
	vector<vector<int>> arr(3, vector<int>(bpv));
	for (int i = 0; i < 3; ++i) {
		int m;
		cin >> m;
		vector<vector<int>> graph(n);
		for (int j = 0; j < m; ++j) {
			int a, b;
			cin >> a >> b;
			--a; --b;
			if (a > b) {
				swap(a, b);
			}
			graph[a].push_back(b);
		}

		vector<int> take(n);

		for (int j = n - 1; j >= 0; --j) {
			set<int> cur;
			for (int to : graph[j]) {
				cur.insert(take[to]);
			}
			while (cur.count(take[j])) {
				++take[j];
			}
			add(arr[i][take[j]], mpow(10, 18 * (j + 1)));
		}
	}

	int ans = 0;

	// add(ans, mult(mult(arr[0][0], arr[1][0]), arr[2][0]));

	// for (int i = 0; i < 3; ++i) {
	// 	for (int j = 1; j < n; ++j) {
	// 		add(ans, mult(arr[i][0], mult(arr[(i + 1) % 3][j], arr[(i + 2) % 3][j])));
	// 	}
	// }

	// for (int x = 0; x < n; ++x) {
	// 	for (int y = 0; y < n; ++y) {
	// 		int z = x ^ y;
	// 		if (z < n) {
	// 			add(ans, mult(arr[0][x], mult(arr[1][y], arr[2][z])));
	// 		}
	// 	}
	// }

	// for (int i = 0; i < 3; ++i) {
	// 	for (int num : arr[0]) {
	// 		cerr << num << " ";
	// 	}
	// 	cerr << endl;
	// }

	transform(arr[0].begin(), arr[0].end());
	transform(arr[1].begin(), arr[1].end());

	for (int i = 0; i < bpv; ++i) {
		arr[0][i] = mult(arr[0][i], arr[1][i]);
	}

	transform(arr[0].begin(), arr[0].end());


	int coef = inv(bpv);
	for (int i = 0; i < bpv; ++i) {
		arr[0][i] = mult(arr[0][i], coef);
	}
	// for (int num : arr[0]) {
	// 	cerr << num << " ";
	// }
	// cerr << endl;

	for (int i = 0; i < bpv; ++i) {
		add(ans, mult(arr[0][i], arr[2][i]));
	}

	cout << ans << "\n";
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}

#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}

Measured memory_bytes: 6396