#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr bool operator==(const modint rhs) const noexcept {return a==rhs.a;}
  constexpr bool operator!=(const modint rhs) const noexcept {return !(*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) 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;
  }
};

/* template end */

using ll = long long;
using P=std::pair<long long,long long>;

constexpr ll MOD=998244353;
using mint=modint<MOD>;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll n;
  std::cin>>n;

  std::vector<std::vector<ll>> x(n),y(n),z(n);

  ll m1;
  std::cin>>m1;
  rep(i,0,m1){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    if(a>b)std::swap(a,b);
    x[a].emplace_back(b);
  }

  ll m2;
  std::cin>>m2;
  rep(i,0,m2){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    if(a>b)std::swap(a,b);
    y[a].emplace_back(b);
  }

  ll m3;
  std::cin>>m3;
  rep(i,0,m3){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    if(a>b)std::swap(a,b);
    z[a].emplace_back(b);
  }

  ll m=std::max({m1,m2,m3});

  constexpr mint INF=mypow(mint(10),18);
  std::vector<mint> pow(n+1,1);
  rep(i,1,n+1)pow[i]=pow[i-1]*INF;

  ll root=0;
  while(root*(root+1)<=2*m)root++;

  std::vector<ll> gru_x(n),gru_y(n),gru_z(n);
  std::vector<mint> val_x(root,0),val_y(root,0),val_z(root,0);

  for(ll i=n-1;i>=0;i--){
    std::vector<ll> flag(root,0);
    for(auto&& e:x[i])flag[gru_x[e]]=1;
    rep(j,0,root){
      if(flag[j]==0){
        gru_x[i]=j;
        val_x[j]+=pow[i+1];
        break;
      }
    }
  }

  for(ll i=n-1;i>=0;i--){
    std::vector<ll> flag(root,0);
    for(auto&& e:y[i])flag[gru_y[e]]=1;
    rep(j,0,root){
      if(flag[j]==0){
        gru_y[i]=j;
        val_y[j]+=pow[i+1];
        break;
      }
    }
  }

  for(ll i=n-1;i>=0;i--){
    std::vector<ll> flag(root,0);
    for(auto&& e:z[i])flag[gru_z[e]]=1;
    rep(j,0,root){
      if(flag[j]==0){
        gru_z[i]=j;
        val_z[j]+=pow[i+1];
        break;
      }
    }
  }

  mint ans=0;

  rep(i,0,root){
    rep(j,0,root){
      if((i^j)<root)ans+=val_x[i]*val_y[j]*val_z[i^j];
    }
  }

  std::cout<<ans.value()<<"\n";

  return 0;
}

Measured memory_bytes: 16384