M,z,s=998244353,1,0

N,*A=list(map(int,open(0)))

d=[1]+[0]*7**6

e=[1]+[0]*7**6

for a in A:

 i=s;s+=a;z*=3

 while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1

i=s

while i*2>=s:z=(z-d[i]*3)%M;i-=1

print(((z+~s%2*e[s//2]*3)%M))
M,z,s=998244353,1,0

d=[1]+[0]*7**6

e=[1]+[0]*7**6

for _ in'_'*eval(input()):

 a=eval(input());s+=a;i=s;z*=3

 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1

i=s

while i*2>=s:z=(z-d[i]*3)%M;i-=1

print((z+~s%2*e[s//2]*3)%M)
M, z, s = 998244353, 1, 0
N, *A = list(map(int, open(0)))
d = [1] + [0] * 7**6
e = [1] + [0] * 7**6
for a in A:
    i = s
    s += a
    z *= 3
    while ~i:
        d[i + a] += d[i] % M
        d[i] *= 2
        e[i + a] += e[i] % M
        i -= 1
i = s
while i * 2 >= s:
    z = (z - d[i] * 3) % M
    i -= 1
print(((z + ~s % 2 * e[s // 2] * 3) % M))

M, z, s = 998244353, 1, 0
d = [1] + [0] * 7**6
e = [1] + [0] * 7**6
for _ in "_" * eval(input()):
    a = eval(input())
    s += a
    i = s
    z *= 3
    while ~i:
        d[i] += d[i] + d[i - a] % M
        e[i] += e[i - a] % M
        i -= 1
i = s
while i * 2 >= s:
    z = (z - d[i] * 3) % M
    i -= 1
print((z + ~s % 2 * e[s // 2] * 3) % M)

-N, *A = list(map(int, open(0))) -for a in A: +for _ in "_" * eval(input()): +    a = eval(input()) +    s += a -    s += a -        d[i + a] += d[i] % M -        d[i] *= 2 -        e[i + a] += e[i] % M +        d[i] += d[i] + d[i - a] % M +        e[i] += e[i - a] % M -print(((z + ~s % 2 * e[s // 2] * 3) % M)) +print((z + ~s % 2 * e[s // 2] * 3) % M)