#include <bits/stdc++.h>
using namespace std;
typedef complex<long double> base;
const double pi=acos(-1.);
const int MX=132132,md=998244353;
int n,m,it,ut,i,x,y,res,u[MX],a[3][MX],mx[3];
long long cnt[3][MX];
vector<int> g[MX];
long long pw10(long long x) {
  if (x==0) return 1LL;
  if (x&1) return (pw10(x-1)*10LL)%md;
  long long z=pw10(x/2);
  return (z*z)%md;
}
int main() {
  scanf("%d",&n);
  for (it=0; it<3; it++) {
    for (i=1; i<=n; i++) g[i].clear();
    scanf("%d",&m);
    while (m--) {
      scanf("%d%d",&x,&y);
      g[min(x,y)].push_back(max(x,y));
    }
    for (i=n; i>0; i--) {
      ++ut;
      for (x=0; x<g[i].size(); x++) u[a[it][g[i][x]]]=ut;
      for (a[it][i]=0; u[a[it][i]]==ut; a[it][i]++);
      cnt[it][a[it][i]]=(cnt[it][a[it][i]]+pw10(18*i))%md;
      mx[it]=max(mx[it],a[it][i]);
    }
  }
  for (i=0; i<=mx[0]; i++) if (cnt[0][i]) for (x=0; x<=mx[1]; x++) if (cnt[1][x] && cnt[2][i^x])
    res=(res+((cnt[0][i]*cnt[1][x])%md)*cnt[2][i^x])%md;
  printf("%d\n",res);
  return 0;
}
