#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

vector<Int> edge[3][110000];
Int grundy[3][110000];
Int grundysum[3][110000];
Int n, m[3], a, b;
bool nums[110000];

Int mod_pow(Int x, Int a, Int m = MOD){
    if(a == 0)return 1;
    Int res = mod_pow(x, a / 2, m);
    res = res * res % m;
    if(a % 2)res *= x;
    return res % m;
}

Int inv(Int x, Int m = MOD){
    return mod_pow(x, m-2, m);
}


void calc(Int x){
    for(Int i = n;i >= 1;i--){
        for(Int neib:edge[x][i]){
            if(neib < i)continue;
            nums[grundy[x][neib]] = true;
        }
        while(nums[grundy[x][i]])grundy[x][i]++;
        for(Int neib:edge[x][i]){
            if(neib < i)continue;
            nums[grundy[x][neib]] = false;
        }
        grundysum[x][grundy[x][i]] += mod_pow(10, 18 * i, MOD2);
        grundysum[x][grundy[x][i]] %= MOD2;
    }
}

int main(){
    cin >> n;
    for(Int i = 0;i < 3;i++){
        cin >> m[i];
        for(Int j = 0;j < m[i];j++){
            cin >> a >> b;
            edge[i][a].push_back(b);
            edge[i][b].push_back(a);
        }
        calc(i);
    }

    Int ans = 0;
    for(Int i = 0;i < 600;i++){
        for(Int j = 0;j < 600;j++){
            ans += grundysum[0][i] * grundysum[1][j] % MOD2 * grundysum[2][i^j] % MOD2;
            ans %= MOD2;
        }
    }
    cout << ans << endl;
    return 0;
}