Given a triplet of integers (X , Y , Z), such that X ≤ Y and Y ≥ Z, we define f(X , Y , Z) to be (X + Y) * (Y + Z). If either X > Y or Y < Z, or both, then f(X , Y , Z) is defined to be 0.
You are provided three arrays  A , B and C   of any length (their lengths may or may not be equal).  
Your task is to find the sum of f(X , Y , Z) over all triplets (X, Y , Z) where   X, Y and Z  belong to  A, B and C respectively.
Output your sum for each test case modulo 1000000007.

-----Input-----
- The first line contains a single integer, T, which is the number of test cases. The description of each testcase follows:
- The first line of each testcase contains 3 integers: p, q and r. These denote the lengths of A,B and C respectively. 
- The second line contains p integers, which are the elements of A
- The third line contains q integers, which are the elements of B
- The fourth line contains r integers, which are the elements of C

-----Output-----
Output the required sum modulo  1000000007  for each test case in a new line.

-----Constraints-----
- 1 ≤ T ≤ 10 
- 1 ≤ p, q, r ≤ 100000 
- 1 ≤ every array element ≤ 1000000000

-----Subtasks  -----
- Subtask #1 (30 points): 1 ≤ p,q,r  ≤ 100 
- Subtask #2 (70 points): 1 ≤ p,q,r  ≤ 100000 

-----Example : -----
Input:
1 
3 1 3
1 2 3
5
4 5 6

Output:
399

-----Explanation: -----
As there is only one choice for Y which equals to 5, to get a non-zero function value,we can choose any element for X from the set { 1 , 2 , 3 } and for Z from the set { 4  , 5 } 
So triplets which give non-zero function values are: 
{ 1 , 5  , 4 } :  ( 1 + 5 ) * ( 5 + 4 )  = 54 
{ 1 , 5  , 5 } :  ( 1 + 5 ) * ( 5 + 5 )  = 60 
{ 2 , 5  , 4 } :  ( 2 + 5 ) * ( 5 + 4 )  = 63 
{ 2 , 5  , 5 } :  ( 2 + 5 ) * ( 5 + 5 )  = 70 
{ 3 , 5  , 4 } :  ( 3 + 5 ) * ( 5 + 4 )  = 72 
{ 3 , 5  , 5 } :  ( 3 + 5 ) * ( 5 + 5 )  = 80 
Final answer : 54 + 60 + 63 + 70 + 72 + 80  = 399

Starter code:

Solutions:
T=int(input()) # cook your dish here
for i in range(T): 
    n=list(map(int,input().split()))
    a=n[0]
    b=n[1]
    c=n[2]
    l=[]
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    for i in range(b):
        for j in range(a):
            for k in range(c):
                if(A[j]<=B[i] and B[i]>=C[k]):
                    sum=((A[j]+B[i])*(B[i]+C[k]))
                    l.append(int(sum))
                
                
            
    
    sum=0
    for i in range(len(l)):
        sum+=int(l[i])
    print(sum%1000000007)

t=int(input())
for i in range(0,t):
    p,q,r=map(int,input().split())
    x=[int(x) for x in input().split()]
    y=[int(x) for x in input().split()]
    z=[int(x) for x in input().split()]
    s=0
    for j in range(0,p):
        for k in range(0,q):
            for l in range(0,r):
                if x[j]>y[k] or y[k]<z[l]:
                    s+=0
                else:
                    s+=(x[j]+y[k])*(y[k]+z[l])
    print(s%(10**9+7))

t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
    p, q, r = map(int, input(). strip(). split())
    a= sorted(int(x) for x in input().split())
    b= sorted(int(x) for x in input().split())
    c= sorted(int(x) for x in input().split())
    ans = 0
    m = 0
    n = 0
    sum1 = 0
    sum2 = 0
    for i in b:
        while m < p and a[m] <= i:
            sum1 += a[m]
            m += 1
        while n < r and c[n] <= i:
            sum2 += c[n]
            n += 1
        ans += (sum1+m*i)*(sum2+n*i)
    print(ans%mod)



t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
    p, q, r = map(int, input(). strip(). split())
    a= sorted(int(x) for x in input().split())
    b= sorted(int(x) for x in input().split())
    c= sorted(int(x) for x in input().split())
    ans = 0
    for i in b:
        m = 0
        n = 0
        sum1 = 0
        sum2 = 0
        while m < p and a[m] <= i:
            sum1 += a[m]
            m += 1
        while n < r and c[n] <= i:
            sum2 += c[n]
            n += 1
        ans += (sum1+m*i)*(sum2+n*i)
    print(ans%mod)



t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
    p, q, r = map(int, input(). strip(). split())
    a = list(map(int, input(). strip(). split()))
    b = list(map(int, input(). strip(). split()))
    c = list(map(int, input(). strip(). split()))
    a.sort()
    b.sort
    c.sort()
    ans = 0
    for i in b:
        m = 0
        n = 0
        sum1 = 0
        sum2 = 0
        while m < p and a[m] <= i:
            sum1 += a[m]
            m += 1
        while n < r and c[n] <= i:
            sum2 += c[n]
            n += 1
        ans += (sum1+m*i)*(sum2+n*i)
    print(ans%mod)



t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
    p, q, r = map(int, input(). strip(). split())
    a = list(map(int, input(). strip(). split()))
    b = list(map(int, input(). strip(). split()))
    c = list(map(int, input(). strip(). split()))
    a.sort()
    c.sort()
    ans = 0
    for i in b:
        m = 0
        n = 0
        sum1 = 0
        sum2 = 0
        while m < p and a[m] <= i:
            sum1 += a[m]
            m += 1
        while n < r and c[n] <= i:
            sum2 += c[n]
            n += 1
        ans += (sum1+m*i)*(sum2+n*i)
    print(ans%mod)



testcases = int(input())
while testcases > 0:
    array_length = list(map(int,input().split()))
    array1 = list(map(int,input().split()))
    array2 = list(map(int, input().split()))
    array3 = list(map(int, input().split()))
    sum = 0
    for i in range(array_length[0]):
        for j in range(array_length[1]):
            if array1[i] <= array2[j]:
                 for k in range(array_length[2]):
                    if array2[j] >= array3[k] :
                        sum = (sum + (((array1[i] + array2[j]) % 1000000007 )*((array2[j]+array3[k]) % 1000000007))) % 1000000007
    print(sum%1000000007)
    testcases -= 1

testcases = int(input())
while testcases > 0:
    array_length = list(map(int,input().split()))
    array1 = list(map(int,input().split()))
    array2 = list(map(int, input().split()))
    array3 = list(map(int, input().split()))
    sum = 0
    for i in range(array_length[0]):
        for j in range(array_length[1]):
            for k in range(array_length[2]):
                if array1[i] <= array2[j] and array2[j] >= array3[k] :
                    sum = (sum + (((array1[i] + array2[j])%1000000007 )*((array2[j]+array3[k]) % 1000000007))) % 1000000007
    testcases -= 1
    print(sum%1000000007)

t = int(input()) 
mod = 10 ** 9 + 7
for _ in range(t):
    sum = 0
    p, q, r = map(int, input().split()) 
    a= sorted(int(x) for x in input().split()) 
    b= sorted(int(x) for x in input().split()) 
    c= sorted(int(x) for x in input().split()) 
    t1=t2 = sum1 = sum2 = 0
    for i in b:
        while t1<p and a[t1]<=i:
            sum1+=a[t1]
            t1+=1
        while t2<r and c[t2]<=i:
            sum2+=c[t2]
            t2+=1
        sum+=(i*t1 + sum1)*(i*t2 + sum2)
    print(sum%mod)    
            

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            if i>=min(a) and i>=min(c):
                for j in a:
                    if j<=i:
                        for k in c:
                            if i>=k:
                                sum = sum + value(j,i,k)
        '''for i in b:
            if i>=min(a) and i>=min(c):
                a1 = [j for j in a if j<=i]
                c1 = [j for j in c if j<=i]
                for j in a1:
                    for k in c1:
                        #if j<=i and i>=k:
                        sum = sum + value(j,i,k)'''
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            for j in a:
                for k in c:
                    if j<=i and i>=k:
                        sum = sum + value(j,i,k)
        '''for i in b:
            if i>=min(a) and i>=min(c):
                a1 = [j for j in a if j<=i]
                c1 = [j for j in c if j<=i]
                for j in a1:
                    for k in c1:
                        #if j<=i and i>=k:
                        sum = sum + value(j,i,k)'''
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            if i>=min(a) and i>=min(c):
                a1 = [j for j in a if j<=i]
                c1 = [j for j in c if j<=i]
                for j in a1:
                    for k in c1:
                        #if j<=i and i>=k:
                        sum = sum + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            if i>=min(a) and i>=min(c):
                a1 = [j for j in a if j<=i]
                c1 = [j for j in c if j<=i]
                for j in a1:
                    for k in c1:
                        #if j<=i and i>=k:
                        sum = sum + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            if i>=min(a) and i>=min(c):
                a1 = [j for j in a if j<=i]
                c1 = [j for j in c if j<=i]
                for j in a1:
                    for k in c1:
                        #if j<=i and i>=k:
                        sum = sum%m + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)%m*(b+c)%m)%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x)%m for x in input().split()]
    b = [int(x)%m for x in input().split()]
    c = [int(x)%m for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            if i>=min(a) and i>=min(c):
                a1 = [j for j in a if j<=i]
                c1 = [j for j in c if j<=i]
                for j in a1:
                    for k in c1:
                        #if j<=i and i>=k:
                        sum = sum%m + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            if i>=min(a) and i>=min(c):
                a1 = [j for j in a if j<=i]
                c1 = [j for j in c if j<=i]
                for j in a1:
                    for k in c1:
                        #if j<=i and i>=k:
                        sum = sum%m + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            a1 = [j for j in a if j<=i]
            c1 = [j for j in c if j<=i]
            for j in a1:
                for k in c1:
                    #if j<=i and i>=k:
                    sum = sum%m + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)%m*(b+c)%m)%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    for i in b:
        a1 = [j for j in a if j<=i]
        c1 = [j for j in c if j<=i]
        for j in a1:
            for k in c1:
                #if j<=i and i>=k:
                sum = sum%m + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    for i in b:
        a1 = [j for j in a if j<=i]
        c1 = [j for j in c if j<=i]
        for j in a1:
            for k in c1:
                #if j<=i and i>=k:
                sum = sum%m + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    if min(a)>max(b) or max(b)<min(c):
        sum=0
    else:
        for i in b:
            for j in a:
                for k in c:
                    if j<=i and i>=k:
                        sum = sum%m + value(j,i,k)
    print(sum%m)                

m = 1000000007
def value(a,b,c):
    return ((a+b)*(b+c))%m

t = int(input())
while(t):
    t-=1
    sum=0
    p,q,r = map(int,input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    for i in b:
        for j in a:
            for k in c:
                if j<=i and i>=k:
                    sum = sum%m + value(j,i,k)
    print(sum%m)                

t = int(input()) 
mod = 10 ** 9 + 7
for _ in range(t):
    p, q, r = map(int, input().split()) 
    A = sorted(int(x) for x in input().split()) 
    B = sorted(int(x) for x in input().split()) 
    C = sorted(int(x) for x in input().split()) 
    m = n = a = b = ans = 0
    for Y in B:
        while m < p and A[m] <= Y:
            a += A[m]
            m += 1 
        while n < r and C[n] <= Y:
            b += C[n]
            n += 1 
        ans += (Y * m + a) * (Y * n + b) 
        ans %= mod 
    print(ans)
        
        

# cook your dish here
t=int(input())
for i in range(t):
    x,y,z=map(int,input().split())
    l=list(map(int,input().split()))
    m=list(map(int,input().split()))
    n=list(map(int,input().split()))
    s=0
    for j in range(x):
        for k in range(y):
            for f in range(z):
                if l[j]<=m[k] and m[k]>=n[f]:
                    s=s+((l[j]+m[k])*(m[k]+n[f]))
    print(s%1000000007)

# cook your dish here
t = int(input())
for p in range(t):
    x,y,z = map(int,input().split())
    l = list(map(int,input().split()))
    m = list(map(int,input().split()))
    n = list(map(int,input().split()))
    s = 0
    for i in l:
        for j in m:
            for k in n:
                if i<=j and j>=k:
                    s = s+(((i+j)*(j+k))%1000000007)
    print(s%1000000007)

# cook your dish here
t = int(input())
for p in range(t):
    x,y,z = map(int,input().split())
    l = list(map(int,input().split()))
    m = list(map(int,input().split()))
    n = list(map(int,input().split()))
    s = 0
    for i in l:
        for j in m:
            for k in n:
                if i<=j and j>=k:
                    s = s+((i+j)*(j+k))
    print(s%1000000007)