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

print((3 ** int(eval(input())) - 2 ** sum(~int(s) % 2 for s in input().split())))

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