s,a,b=[set(map(int,input().split()))for j in[0]*3];c=1;N=M=0;x=max(a)

for k in range(x,0,-1):

 A=k in a;B=k in b

 if A and B:M+=1;N+=1

 elif A:c*=M;N+=1

 elif B:c*=N;M+=1

 else:c*=M*N-x+k

 c%=10**9+7

print(c)
s,a,b=[set(map(int,input().split()))for j in[0]*3];c=1;N=M=0;k=x=max(a)

while k:A=k in a;B=k in b;N+=A;M+=B;c*=[M*N-x+k,N,M,1][A*2+B];c%=10**9+7;k-=1

print(c)
s, a, b = [set(map(int, input().split())) for j in [0] * 3]
c = 1
N = M = 0
x = max(a)
for k in range(x, 0, -1):
    A = k in a
    B = k in b
    if A and B:
        M += 1
        N += 1
    elif A:
        c *= M
        N += 1
    elif B:
        c *= N
        M += 1
    else:
        c *= M * N - x + k
    c %= 10**9 + 7
print(c)

s, a, b = [set(map(int, input().split())) for j in [0] * 3]
c = 1
N = M = 0
k = x = max(a)
while k:
    A = k in a
    B = k in b
    N += A
    M += B
    c *= [M * N - x + k, N, M, 1][A * 2 + B]
    c %= 10**9 + 7
    k -= 1
print(c)

-x = max(a) -for k in range(x, 0, -1): +k = x = max(a) +while k: -    if A and B: -        M += 1 -        N += 1 -    elif A: -        c *= M -        N += 1 -    elif B: -        c *= N -        M += 1 -    else: -        c *= M * N - x + k +    N += A +    M += B +    c *= [M * N - x + k, N, M, 1][A * 2 + B] +    k -= 1