#include <bits/stdc++.h>
#define Maxn 100007
#define modp 998244353
using namespace std;
int base=1;
int n,m1,m2,m3;
int n1,n2,n3,val1[Maxn],val2[Maxn],val3[Maxn],val[3*Maxn];
vector<int> e1[Maxn],e2[Maxn],e3[Maxn];
bool vis[Maxn],flag[Maxn];
bool vis1[2007][2007],vis2[2007][2007],vis3[2007][2007];
void solve1()
{
    n1=0;
    bool chk=true;
    memset(vis,false,sizeof(vis));
    while (chk)
    {
        memset(flag,true,sizeof(flag));
        chk=false;
        for (int i=n;i;i--)
            if ((!vis[i])&&flag[i])
            {
                vis[i]=true;
                if (!chk)
                {
                    chk=true;
                    val1[++n1]=val[i];
                } else val1[n1]=(val1[n1]+val[i])%modp;
                for (int j=0;j<(int)e1[i].size();j++)
                    flag[e1[i][j]]=false;
            }
    }
}
void solve2()
{
    n2=0;
    bool chk=true;
    memset(vis,false,sizeof(vis));
    while (chk)
    {
        memset(flag,true,sizeof(flag));
        chk=false;
        for (int i=n;i;i--)
            if ((!vis[i])&&flag[i])
            {
                vis[i]=true;
                if (!chk)
                {
                    chk=true;
                    val2[++n2]=val[i];
                } else val2[n2]=(val2[n2]+val[i])%modp;
                for (int j=0;j<(int)e2[i].size();j++)
                    flag[e2[i][j]]=false;
            }
    }
}
void solve3()
{
    n3=0;
    bool chk=true;
    memset(vis,false,sizeof(vis));
    while (chk)
    {
        memset(flag,true,sizeof(flag));
        chk=false;
        for (int i=n;i;i--)
            if ((!vis[i])&&flag[i])
            {
                vis[i]=true;
                if (!chk)
                {
                    chk=true;
                    val3[++n3]=val[i];
                } else val3[n3]=(val3[n3]+val[i])%modp;
                for (int j=0;j<(int)e3[i].size();j++)
                    flag[e3[i][j]]=false;
            }
    }
}
int main()
{
    for (int i=1;i<=18;i++)
        base=(10LL*base)%modp;
    scanf("%d",&n);
    val[0]=1;
    for (int i=1;i<=3*n;i++)
        val[i]=(1LL*val[i-1]*base)%modp;
    scanf("%d",&m1);
    for (int i=1;i<=m1;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        e1[u].push_back(v);
        e1[v].push_back(u);
    }
    scanf("%d",&m2);
    for (int i=1;i<=m2;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        e2[u].push_back(v);
        e2[v].push_back(u);
    }
    scanf("%d",&m3);
    for (int i=1;i<=m3;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        e3[u].push_back(v);
        e3[v].push_back(u);
    }
    solve1();
    solve2();
    solve3();
    int ans=0;
    memset(vis1,true,sizeof(vis1));
    memset(vis2,true,sizeof(vis2));
    memset(vis3,true,sizeof(vis3));
    for (int x=3;x<=n1+n2+n3;x++)
        for (int i=1;i<=n1;i++)
            for (int j=1;j<=n2;j++)
            {
                int k=x-i-j;
                if (k>=1&&k<=n3)
                {
                    if (vis1[i][j]&&vis2[j][k]&&vis3[k][i])
                    {
                        vis1[i][j]=false;
                        vis2[j][k]=false;
                        vis3[k][i]=false;
                        int tmp=(1LL*val1[i]*val2[j])%modp;
                        tmp=(1LL*tmp*val3[k])%modp;
                        ans=(ans+tmp)%modp;
                    }
                }
            }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 32364