/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include<vector>

constexpr ll mod17 = 1e9+7;
constexpr ll mod19 = 1e9+9;
constexpr ll mod9 = 998244353;
ll mod = mod17;

// Mod int library
unordered_map<ll, ll> minvmap;
ll minv(ll a, ll m) {
  auto k = a; auto p = minvmap[a]; if (p != 0) return p;
  ll b = m, u = 1, v = 0;
  while (b) { ll t = a/b; swap(a -= t*b, b); swap(u -= t*v, v); }
  p = (u%m+m)%m; minvmap[k] = p; return p;
}

struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  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){ (x*=minv(a.x, mod))%=mod; return *this; }
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  mint operator/(const mint& a)const{ return mint(*this) /= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};

template<typename T>
T mod_pow(T a, ll x) {
  T res = 1;
  while(x > 0) {
    if (x & 1) res *= a;
    a *= a; x >>= 1;
  }
  return res;
}

class combination {
    // factorial
    public: std::vector<mint> fact;
    public: std::vector<mint> inv;

    combination(int n) {
      fact.resize(n + 1);
      inv.resize(n + 1);
      fact[0] = 1;
      for (int i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i;
      }
      inv[n] = mint(1) / fact[n];
      for (int i = n - 1; i >= 0; i--) {
        inv[i] = inv[i + 1] * (i + 1);
      }
    }

    // nCr
    public: mint get(int n, int r) {
      if (n < r || n < 0 || r < 0) return 0;
      return fact[n]*inv[r]*inv[n-r];
    }
    // nPr
    public: mint p(int n, int r) {
      if (n < r || n < 0) return 0;
      return fact[n]*inv[n-r];
    }
};

class CGiantGraph {
public:

    vector<vector<int>> ga, gb, gc;
    vector<int> gra, grb, grc;
    vector<int> tmp;
    void func(vector<vector<int>>& g, vector<int>& gr, int n) {
      gr[n-1] = 0;
      for(int i=n-2; i>=0; i--) {
        vector<int> v;
        for(auto e : g[i]) {
          if (e > i) {
            tmp[gr[e]]++;
            v.push_back(gr[e]);
          }
        }
        rep(j, 1000) {
          if (tmp[j] == 0) {
            gr[i] = j;
            break;
          }
        }
        for(auto e: v) {
          tmp[e]--;
        }
      }
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      mod = mod9;
      int n; cin >> n;
      tmp.resize(1000);
      ga.resize(n, vector<int>());
      gb.resize(n, vector<int>());
      gc.resize(n, vector<int>());
      gra.resize(n);
      grb.resize(n);
      grc.resize(n);
      vector<mint> suma(1000), sumb(1000), sumc(1000);
      int m; cin >> m;
      rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        ga[a].push_back(b);
        ga[b].push_back(a);
      }
      cin >> m;
      rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        gb[a].push_back(b);
        gb[b].push_back(a);
      }
      cin >> m;
      rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        gc[a].push_back(b);
        gc[b].push_back(a);
      }
      func(ga, gra, n);
      func(gb, grb, n);
      func(gc, grc, n);


      mint base = mod_pow(mint(10), 18);
      rep(i, n) {
        suma[gra[i]] += mod_pow(base, i+1);
        sumb[grb[i]] += mod_pow(base, i+1);
        sumc[grc[i]] += mod_pow(base, i+1);
      }

      mint ans = 0;
      rep(i, 1000) {
        rep(j, 1000) {
          int k = i^j;
          if (k >= 1000) continue;
          ans += suma[i]*sumb[j]*sumc[k];
        }
      }
      cout << ans.x << endl;
    }
};

signed main() {
  CGiantGraph solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 16896