n = int(eval(input()))

a = sum(list([1-int(x)%2 for x in input().split()]))

print((3**n-2**a))

print((3**int(eval(input()))-2**sum(list([1-int(x)%2 for x in input().split()]))))

n = int(eval(input()))
a = sum(list([1 - int(x) % 2 for x in input().split()]))
print((3**n - 2**a))

print(
    (
        3 ** int(eval(input()))
        - 2 ** sum(list([1 - int(x) % 2 for x in input().split()]))
    )
)

-n = int(eval(input())) -a = sum(list([1 - int(x) % 2 for x in input().split()])) -print((3**n - 2**a)) +print( +    ( +        3 ** int(eval(input())) +        - 2 ** sum(list([1 - int(x) % 2 for x in input().split()])) +    ) +)