#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
#define INF 100000000
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}





void go();

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15);
    int tc=1;
    // tc=in();
    while(tc--){
        go();
    }
    return 0;
}

const ll MOD=998244353;
const int N=1100000;
 
template <ll Modulus> class modint {
  using u64 = ll;
 
public:
  u64 a;
 
  constexpr modint(const u64 x = 0) noexcept : a(((x % Modulus) + Modulus)%Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
 
#define mint modint<MOD>
mint inv[N],comb[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N-1){
        inv[i]=inv[MOD%i]*(-MOD/i);
    }
    return;
}
void calc_product(){
    prd[0]=prd[1]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N-1){
        prd[i]=prd[i-1]*i;
        invprd[i]=inv[i]*invprd[i-1];
    }
    return ;
}
mint cmb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return {prd[a]*invprd[b]*invprd[a-b]};
}
mint modpow(mint x,ll n){
    if(n==0) return 1;
    mint res=modpow(x*x,n/2);
    if(n&1) res=res*x;
    return res;
}
void calc(){calc_inv();calc_product();}
using vmint = vector<mint> ;




int xy[710][710],xz[710][710],yz[710][710];


void go(){
    int n=in();
    vector<vec> g1(n+1),g2(n+1),g3(n+1);
    int m1=in();
    rep(i,m1){
        int x=in(),y=in();
        g1[x].pb(y);
        g1[y].pb(x);
    }
    int m2=in();
    rep(i,m2){
        int x=in(),y=in();
        g2[x].pb(y);
        g2[y].pb(x);
    }
    int m3=in();
    rep(i,m3){
        int x=in(),y=in();
        g3[x].pb(y);
        g3[y].pb(x);
    }
    vector<int> d1(n+1),d2(n+1),d3(n+1);
    mint T = modpow(10,18);
    vmint P={1};
    rep(i,310000)P.pb(P.back()*T);
    vmint D1(n+1),D2(n+1),D3(n+1);
    rep3(i,n,1){
        set<int> se;
        for(auto e:g1[i]){
            if(e>i)se.insert(d1[e]);
        }
        int gr=0;
        for(auto e:se)if(e==gr)gr++;else break;
        d1[i]=gr;
        D1[gr] += P[i];
    }
    rep3(i,n,1){
        set<int> se;
        for(auto e:g2[i]){
            if(e>i)se.insert(d2[e]);
        }
        int gr=0;
        for(auto e:se)if(e==gr)gr++;else break;
        d2[i]=gr;
        D2[gr] += P[i];
    }
    rep3(i,n,1){
        set<int> se;
        for(auto e:g3[i]){
            if(e>i)se.insert(d3[e]);
        }
        int gr=0;
        for(auto e:se)if(e==gr)gr++;else break;
        d3[i]=gr;
        D3[gr] += P[i];
    }
    vec a,b;
    mint ans;
    int k1=0,k2=0,k3=0;
    rep(i,700){
        rep(j,700){
            rep(k,700){
                if(i>n or j>n or k>n)break;
                if(xy[i][j]==0 and xz[i][k]==0 and yz[j][k]==0) {
                    ans+=D1[i]*D2[j]*D3[k];
                    xy[i][j]=1;
                    xz[i][k]=1;
                    yz[j][k]=1;
                } 
            }
        }
    }

    cout<<ans.a<<endl;
}


Measured memory_bytes: 29168