CodeEff/ECCO huggingface dataset:
# Original solution
from collections import defaultdict

M = 998244353
B = 10**18 % M

def mex(s):
  for i in range(max(s)+2):
    if i not in s:
      return i

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in sorted(list(e.keys()), reverse=True):
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      x = pow(B, i, M)
      sum_g[m] += x
      sum_g[0] -= x
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz)%M
  return ret

N = int(eval(input()))
edge = [read_edge() for i in range(3)]

print((solve(N, edge)))

# Optimized solution
from collections import defaultdict

M = 998244353
B = 10**18 % M

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in sorted(list(e.keys()), reverse=True):
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      x = pow(B, i, M)
      sum_g[m] += x
      sum_g[0] -= x
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz)%M
  return ret

N = int(eval(input()))
edge = [read_edge() for i in range(3)]

print((solve(N, edge)))
# Original solution
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      x = pow(B, i, M)
      sum_g[m] += x
      sum_g[0] -= x
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = ret + sx*sy*sz
  return ret%M


edge = [read_edge() for i in range(3)]

print((solve(N, edge)))

# Optimized solution
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      x = pow(B, i, M)
      sum_g[m] += x
      sum_g[0] -= x
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret += (sx*sy*sz) % M
  return ret%M


edge = [read_edge() for i in range(3)]

print((solve(N, edge)))
# Original solution
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  x = 1
  for i in range(1, N+1):
    x = (x * B) % M
    if i in g:
      sum_g[g[i]] = (sum_g[g[i]] + x) % M
      sum_g[0]  = (sum_g[0] - x) % M
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret


edge = [read_edge() for i in range(3)]

print((solve(N, edge)))

# Optimized solution
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0]  = (sum_g[0] - BB[i]) % M

  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret


edge = [read_edge() for i in range(3)]

print((solve(N, edge)))
# Original solution
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in set(e[i])})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0]  = (sum_g[0] - BB[i]) % M

  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret


edge = [read_edge() for i in range(3)]

print((solve(N, edge)))

# Optimized solution
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in set(e[i])})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0]  = (sum_g[0] - BB[i]) % M

  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret


edge = [read_edge() for i in range(3)]

print((solve(N, edge)))
# Original solution
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0]  = (sum_g[0] - BB[i]) % M

  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret


edge = [read_edge() for i in range(3)]

print((solve(N, edge)))

# Optimized solution
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0]  = (sum_g[0] - BB[i]) % M

  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret


edge = [read_edge() for i in range(3)]

print((solve(N, edge)))
# Original solution
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  prev_i = 1
  W = B
  for i in range(1, N+1):
    if i in g:
      W = (W * pow(B, i-prev_i, M)) % M
      sum_g[g[i]] = (sum_g[g[i]] + W) % M
      sum_g[0]  = (sum_g[0] - W) % M
      prev_i, W = i, W
  
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print((solve(N, edge)))

# Optimized solution
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  prev_i = 0
  W = 1
  for i in range(1, N+1):
    if i in g:
      if i-prev_i != 1:
        W = (W * pow(B, i-prev_i, M)) % M
      else:
        W = (W * B) % M
      sum_g[g[i]] = (sum_g[g[i]] + W) % M
      sum_g[0]  = (sum_g[0] - W) % M
      prev_i, W = i, W
  
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in list(sum_g[0].items()):
    for gy, sy in list(sum_g[1].items()):
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print((solve(N, edge)))
# Original solution
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

M = 998244353 # < (1 << 30)

def mod_inv(a, M=M):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, M
  while abs(z1) != 1:
    d, m = divmod(z2, z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1*z1%M

R_bits = 30
R = 1 << R_bits
R_dec = R - 1
R2 = pow(R, 2, M)
M_neg_inv = mod_inv(-M, R)

def MR(x):
  b = (x * M_neg_inv) & R_dec
  t = x + b * M
  c = t >> R_bits
  d = c - M
  return d if 0 <= d else c

def Montgomery(x):
  return MR(x*R2)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(edge):
  grundy = [{} for i in range(3)]
  sum_g = [defaultdict(int, {0:M_W_sum}) for i in range(3)]
  M_W = M_W_last
  for i in range(N, 0, -1):
    for g, s, e in zip(grundy, sum_g, edge):
      if i in e:
        m = mex({g.get(j, 0) for j in e[i]})
        if m:
          g[i] = m
          s[g[i]] +=  M_W
          s[0] -=  M_W
    M_W = MR(M_W * M_B_inv)
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

N = int(eval(input()))
B = pow(10, 18, M)
M_B_inv = Montgomery(mod_inv(B))
M_W_last = Montgomery(pow(B, N, M))
M_W_sum = MR((M_W_last - Montgomery(1)) * MR(Montgomery(B) * Montgomery(mod_inv(B-1))))

edge = [read_edge() for i in range(3)]
sum_g = calc_grundy(edge)
ans = 0
for gx, sx in list(sum_g[0].items()):
  for gy, sy in list(sum_g[1].items()):
    gz = gx^gy
    sz = sum_g[2][gz]
    if sz:
      ans += MR(MR(sx*sy)*sz)
print((MR(ans)%M))


# Optimized solution
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

def mod_inv(a):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, M
  while z1 != 1:
    d, m = divmod(z2, z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1%M

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  return g

def sum_grundy(grundy):
  sum_g = [defaultdict(int, {0:B_sum}) for i in range(3)]
  W, prev = B, 1
  for i in range(1, N+1):
    for s, g in zip(sum_g, grundy):
      if i in g:
        if prev != i:
          W, prev = W * pow(B, i-prev, M) % M, i
        s[g[i]] =  (s[g[i]] + W) % M
        s[0] =  (s[0] - W) % M
  return sum_g

def read_edge():
  M = int(eval(input()))
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

N = int(eval(input()))
M = 998244353
B = pow(10, 18, M)
B_sum = (pow(B, N+1, M) - B) * mod_inv(B-1) % M

edge = [read_edge() for i in range(3)]
grundy = list(map(calc_grundy, edge))
sum_g = sum_grundy(grundy)
ans = 0
for gx, sx in list(sum_g[0].items()):
  for gy, sy in list(sum_g[1].items()):
    gz = gx^gy
    if gz in sum_g[2]:
      ans = (ans + sx*sy*sum_g[2][gz]) % M
print(ans)
# Original solution
def calc():
    def mex(i):
        D = {}
        for j in X[i]:
            D[G[j]] = 1
        for g in range(N + 1):
            if g not in D:
                return g
    M = int(eval(input()))
    X = [[] for _ in range(N)]
    for _ in range(M):
        a, b = list(map(int, input().split()))
        X[N - min(a, b)].append(N - max(a, b))
    G = [0] * N
    for i in range(N):
        G[i] = mex(i)
    H = [0] * 1024
    a = 1
    for i in range(N)[::-1]:
        a = a * A % P
        H[G[i]] = (H[G[i]] + a) % P
    return H

P = 998244353
A = pow(10, 18, P)
N = int(eval(input()))
H1, H2, H3 = calc(), calc(), calc()
ans = 0
for i in range(1024):
    if H1[i] == 0: continue
    for j in range(1024):
        if H2[j] == 0: continue
        ans = (ans + H1[i] * H2[j] * H3[i^j]) % P

print(ans)

# Optimized solution
import sys
input = lambda: sys.stdin.readline().rstrip()

def calc():
    def mex(i):
        t = 0
        for j in X[i]:
            t |= 1 << G[j]
        t = ~t
        return (t & -t).bit_length() - 1
    M = int(eval(input()))
    X = [[] for _ in range(N)]
    for _ in range(M):
        a, b = list(map(int, input().split()))
        X[N - min(a, b)].append(N - max(a, b))
    G = [0] * N
    for i in range(N):
        G[i] = mex(i)
    H = [0] * 1024
    a = 1
    for i in range(N)[::-1]:
        a = a * A % P
        H[G[i]] = (H[G[i]] + a) % P
    return H

P = 998244353
A = pow(10, 18, P)
N = int(eval(input()))
H1, H2, H3 = calc(), calc(), calc()
ans = 0
for i in range(1024):
    if H1[i] == 0: continue
    for j in range(1024):
        if H2[j] == 0: continue
        ans = (ans + H1[i] * H2[j] * H3[i^j]) % P

print(ans)
# Original solution
N = int(eval(input()))
S = [int(eval(input())) for i in range(N)]
dp = {}
dp[0] = True

for s in S:
    keys = list(dp.keys())
    for k in keys:
        dp[k + s] = True

res = 0
for k in list(dp.keys()):
    if k % 10 == 0:
        continue
    res = max(res, k)

print(res)


# Optimized solution
N = int(eval(input()))
S = [int(eval(input())) for i in range(N)]
T = list([x for x in S if x % 10 > 0])
res = sum(S)
if res % 10 == 0:
    if len(T) == 0:
        res = 0
    else:
        res -= min(T)

print(res)
# Original solution
n=int(eval(input()))
s=[int(eval(input())) for i in range(n)]
memo=[[0]*20000 for i in range(200)]
def dp(score, i):
    if i==n:
        if score%10==0:
            memo[i][score]=0
            return 0
        else:
            memo[i][score]=score
            return score
    if memo[i][score]>0:
        return memo[i][score]
    memo[i][score]=max(dp(score+s[i-1], i+1), dp(score, i+1))
    return memo[i][score]
print((dp(0,0)))

# Optimized solution
n=int(eval(input()))
s=[int(eval(input())) for i in range(n)]
memo=[[-1]*20000 for i in range(200)]
def dp(score, i):
    if i==n:
        if score%10==0:
            memo[i][score]=0
            return 0
        else:
            memo[i][score]=score
            return score
    if memo[i][score]>=0:
        return memo[i][score]
    memo[i][score]=max(dp(score+s[i-1], i+1), dp(score, i+1))
    return memo[i][score]
print((dp(0,0)))
# Original solution
import itertools

N = int(eval(input()))

lst = []
# listにN個の数値を格納
for i in range(N):
    lst.append(int(eval(input())))

l_sum = sum(lst)

p_list = []

if l_sum % 10 == 0:
    
    # enumerate()関数を使うと、forループの中でリスト（配列）インデックス番号（カウント、順番）を取得できる
    # i にインデックス番号が入る

    for i, _ in enumerate(lst, 1):
        # permutations()を使うと 第2引数分の全パターンを取得できる
        for j in itertools.permutations(lst, r=i):  # rには1、2、3と渡される
            p_list.append(j)

    q_list = sorted(set(list(map(sum, p_list))),reverse=True)
    x = 0
    for i, item in enumerate(q_list, 1):
        if item % 10 != 0 :
            print(item)
            exit(0)
    
    if x == 0:
        print((0))

else:
    print (l_sum)




# Optimized solution
N = int(eval(input()))

lst = []
# listにN個の数値を格納
for i in range(N):
    lst.append(int(eval(input())))

lst.sort()
lstsum = sum(lst)
p_list = [ i / 10 for i in lst if i % 10 != 0 ]

if len(p_list) == 0:
    print((0))
elif lstsum % 10 != 0:
    print(lstsum)
else:
    for i in range(N):
        ans = lstsum - lst[i]
        if ans % 10 != 0:
            print(ans)
            exit(0)
# Original solution
N = int(eval(input()))
nums=[int(eval(input())) for _ in range(N)]
MAX = 10*4
sum_num = sum(nums)
dp = [0] * (sum_num+1)
dp[0] = 1
for num in nums:
  for i in range(sum_num+1)[::-1]:
    if dp[i] == 1 and i + num <= sum_num:
      dp[i+num] = 1
ans = 0
for i in range(sum_num+1):
  if dp[i] == 1 and i%10 != 0:
    ans = i
print(ans)


# Optimized solution
N = int(eval(input()))
nums=[int(eval(input())) for _ in range(N)]
sum_num = sum(nums)
dp = [0] * (sum_num+1)
dp[0] = 1
for num in nums:
  for i in range(sum_num+1)[::-1]:
    if dp[i] == 1 and i + num <= sum_num:
      dp[i+num] = 1
ans = 0
for i in range(sum_num+1):
  if dp[i] == 1 and i%10 != 0:
    ans = i
print(ans)