#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define inv2 499122177
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
    #define N 100000

    int fac[N+100],invfac[N+100];

    int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
    int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
    int mul(int x,int y) {return 1ll*x*y%maxd;}
    ll qpow(ll x,int y)
    {
        ll ans=1;
        while (y)
        {
            if (y&1) ans=mul(ans,x);
            x=mul(x,x);y>>=1;
        }
        return ans;
    }
    int getinv(int x) {return qpow(x,maxd-2);}

    int C(int n,int m)
    {
        if ((n<m) || (n<0) || (m<0)) return 0;
        return mul(mul(fac[n],invfac[m]),invfac[n-m]);
    }

    void math_init()
    {
        fac[0]=invfac[0]=1;
        rep(i,1,N) fac[i]=mul(fac[i-1],i);
        invfac[N]=getinv(fac[N]);
        per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
    }
    #undef N
}
using namespace My_Math;

void fwt(int lim,int *a,int typ)
{
    for (int mid=1;mid<lim;mid<<=1)
    {
        int len=(mid<<1);
        for (int sta=0;sta<lim;sta+=len)
        {
            rep(j,0,mid-1)
            {
                int x=a[sta+j],y=a[sta+j+mid];
                a[sta+j]=add(x,y);a[sta+j+mid]=dec(x,y);
                if (typ==-1) {a[sta+j]=mul(a[sta+j],inv2);a[sta+j+mid]=mul(a[sta+j+mid],inv2);}
            }
        }
    }
}

int n,m,sg[N],a[N<<1],b[N<<1],c[N<<1],pw[N<<2],lim,f[N<<2];
vi sq[N];
bool vis[N];

void calc(int *a)
{
    m=read();
    rep(i,1,n) {sg[i]=0;sq[i].clear();}
    rep(i,1,m)
    {
        int u=read(),v=read();
        if (u>v) swap(u,v);
        sq[u].pb(v);
    }
    per(u,n,1)
    {
        int len=sq[u].size();
        rep(i,0,len-1)
        {
            int v=sq[u][i];
            vis[sg[v]]=1;
        }
        while (vis[sg[u]]) sg[u]++;
        a[sg[u]]=add(a[sg[u]],pw[u]);
        rep(i,0,len-1)
        {
            int v=sq[u][i];
            vis[sg[v]]=0;
        }
    }
    //cout << endl;
    //rep(i,1,n) cout << sg[i] <<" ";cout << endl;
    fwt(lim,a,1);
}

int main()
{
    n=read();
    lim=1;ll tmp=1e18;tmp%=maxd;
    while (lim<n) lim<<=1;
    pw[0]=1;
    rep(i,1,n) pw[i]=mul(pw[i-1],tmp);
    //rep(i,0,n) cout << pw[i] << " ";cout << endl;
    calc(a);calc(b);calc(c);
    rep(i,0,lim-1) f[i]=mul(mul(a[i],b[i]),c[i]);
    fwt(lim,f,-1);
    printf("%d",f[0]);
    return 0;
}

Measured memory_bytes: 11584