#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx")
#include "bits/stdc++.h"
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=998244353;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#ifdef ONLINE_JUDGE
#define assert(...) /* nothing */
#endif
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
int rint();char rch();long long rlong();
// mt19937 rng; rng.seed(std::chrono::high_resolution_clock::now().time_since_epoch().count());
// template<typename T> int bins(vector<T> &v, T key) {int imin=0,imax=v.size();while(imin<imax) {int imid=(imin+imax)>>1;if (v[imid]<key) imin=imid+1;else imax=imid;}return imin;}

struct mint {
  unsigned x;
  inline int _norm(int x) {
    if (x<0) x+=MOD;
    return x;
  }
  mint() : x(0) {}
  mint(signed sig) {sig=_norm(sig); x=sig;}
  mint(signed long long sig) {sig=_norm(sig%MOD); x=sig;}
  int get() const { return (int)x; }
 
  mint &operator+=(mint that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
  mint &operator-=(mint that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
  mint &operator*=(mint that) { x = ((unsigned long long)x * that.x) % MOD; return *this; }
  mint &operator/=(mint that) { return *this *= that.inverse(); }

  mint &operator+=(int that) {that=_norm(that); if((x += that) >= MOD) x -= MOD; return *this; }
  mint &operator-=(int that) {that=_norm(that); if((x += MOD - that) >= MOD) x -= MOD; return *this; }
  mint &operator*=(int that) {that=_norm(that); x = ((unsigned long long)x * that) % MOD; return *this; }
  mint &operator/=(int that) {that=_norm(that); return *this *= mint(that).inverse(); }

  mint operator+(mint that) const { return mint(*this) += that; }
  mint operator-(mint that) const { return mint(*this) -= that; }
  mint operator*(mint that) const { return mint(*this) *= that; }
  mint operator/(mint that) const { return mint(*this) /= that; }

  mint operator+(int that) const { return mint(*this) += that; }
  mint operator-(int that) const { return mint(*this) -= that; }
  mint operator*(int that) const { return mint(*this) *= that; }
  mint operator/(int that) const { return mint(*this) /= that; }


  mint inverse() const {
    signed a = x, b = MOD, u = 1, v = 0;
    while(b) {
      signed t = a / b;
      a -= t * b; std::swap(a, b);
      u -= t * v; std::swap(u, v);
    }
    if(u < 0) u += MOD;
    mint res; res.x = (unsigned)u;
    return res;
  }
 
  bool operator==(mint that) const { return x == that.x; }
  bool operator!=(mint that) const { return x != that.x; }
  mint operator-() const { mint t; t.x = x == 0 ? 0 : MOD - x; return t; }
  mint operator^(unsigned long long k) const {
    // 0^0 is 1. k must be taken modulo phi(MOD) (MOD-1 if prime) and NOT MOD itself
    mint a=(*this);
    mint r = 1;
    while(k) {
      if(k & 1) r *= a;
      a *= a;
      k >>= 1;
    }
    return r;
  }
};

int mex(vi a) {
  int n=a.size();
  for (int p=0;p<n;p++) {
    while(a[p]!=p) {
      int v=a[p];
      if (0<=v && v<n && a[v]!=v) {
        swap(a[p],a[v]);
      } else {
        break;
      }
    }
  }
  for (int p=0;p<n;p++) {
    if (a[p]!=p) return p;
  }
  return n;
}

vector<mint> pten;
vector<mint> getnim(int n) {
  int m; cin>>m;
  vvi g(n+1);
  for (int k=0;k<m;k++) {
    int a,b; cin>>a>>b;
    if (a>b) swap(a,b);
    g[a].PB(b);
  }
  vi nim(n+1);
  nim[n]=0;
  for (int x=n-1;x>=1;x--) {
    vi v; for (auto &y:g[x]) v.PB(nim[y]);
    nim[x]=mex(v);
  }
  int maxnim=0;
  for (auto &w:nim) chkmax(maxnim,w);
  vector<mint> a(maxnim+1);
  for (int x=1;x<=n;x++) {
    a[nim[x]]+=pten[x];
  }
  return a;
}
int ilog2(int x) {return 31-__builtin_clz(x);}
void rst(vector<mint> & f) {
  for (auto &w:f) w=0;
}
int main() 
{
  int n; cin>>n;
  pten.resize(n+1);
  pten[0]=1;
  int ten=(1000000000000000000LL % MOD);
  for (int x=1;x<=n;x++) pten[x]=pten[x-1]*ten;
  vector<mint> a[3];
  int maxnim=0;
  for (int k=0;k<3;k++) {
    a[k]=getnim(n);
    chkmax(maxnim, (int)a[k].size());
  }
  maxnim = 1<<(1+ilog2(maxnim-1));
  for (int k=0;k<3;k++) a[k].resize(maxnim);
  vector<mint> f[2];
  for (int k=0;k<2;k++) f[k].resize(maxnim);
  int cur=0,nxt=1;
  f[cur]=a[0];
  for (int k=1;k<3;k++) {
    rst(f[nxt]);
    for (int x=0;x<maxnim;x++) {
      mint now=f[cur][x];
      if (now.get()) {
        if (k==2) {
          f[nxt][0]+=now * a[k][x];
        } else {
          for (int y=0;y<maxnim;y++) {
            f[nxt][x^y]+=now * a[k][y];
          }
        }
      }
    }
    swap(cur,nxt);
  }
  mint ans=f[cur][0];
  printf("%d\n",ans.get());
}

/*
int mex2(vi a) {
  sort(a.begin(),a.end());
  int ans=0;
  for (auto &w:a) {
    if (w==ans) ++ans;
  }
  return ans;
}
void bf() {
  int n=1+rand()%7;
  vi a(n);
  for (int x=0;x<n;x++) {
    a[x]=(rand()%10)-4;
  }
  int ans1=mex(a);
  int ans2=mex2(a);
  if (ans1!=ans2) {
    for (auto &w:a) printf("%d ",w);
    printf("\nsmart:%d bf:%d\n",ans1,ans2);
    exit(1);
  }
}
  srand(time(0));
  for (int k=0;k<10000000;k++) {
    bf();
  }
  printf("OK\n");
*/




static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof (stdinBuffer);
static const char* stdinPos = stdinDataEnd;

void readAhead(size_t amount)
{
    size_t remaining = stdinDataEnd - stdinPos;
    if (remaining < amount) {
       memmove(stdinBuffer, stdinPos, remaining);
       size_t sz = fread(stdinBuffer + remaining, 1, sizeof (stdinBuffer) - remaining, stdin);
       stdinPos = stdinBuffer;
       stdinDataEnd = stdinBuffer + remaining + sz;
       if (stdinDataEnd != stdinBuffer + sizeof (stdinBuffer))
         *stdinDataEnd = 0;
    }
}

int rint()
{
    readAhead(16);

    int x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
char rch()
{
    readAhead(16);
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    char ans=*stdinPos;
    ++stdinPos;
    return ans;
}
long long rlong()
{
    readAhead(32);

    long long x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}

Measured memory_bytes: 5328