zeke-and-his-penny
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

Zeke loves to spend time with Penny and likes her. Penny is having an issue to solve a mathematics problem and is confused. She seeks Zeke's help as she feels he could help her with the problem. He finds this problem very simple. The problem is to count the number of unique triplets of different numbers (N1, N2, N3), where Ni could be any positive integer from 1 to Ni, inclusive (i = 1, 2, 3). Here the numbers can not be repeated in a triplet set.

This looks simple right?

But oops !!!! There is a catch here which was missed by Zeke that the numbers N1, N2, N3 could be well up to 10^18. 

Zeke finds it difficult due to large numbers in stake and needs your help for them so that he can give a solution to Penny. You need to find an optimal solution of the number of unique triplets possible which the above conditions satisfied.

Since, the answer could be quite large. Hence you should output it modulo 10^9 + 7. 

Input:

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. 
Each line of a test case contains three space-separated integers N1, N2, N3.
Output:

For each test case, output a single line containing the number of required triples modulo 10^9 + 7.
Constraints
    1 ≤ T ≤ 10^3
    1 ≤ Ni ≤ 10^18
Sample Input:
5
3 3 3
2 3 2
29 11 1994
1 2 3
1 1 50

Sample Output:
6
2
613536
1
0

Explanation

Case 1. We have the following triples composed of different numbers up to 3:

(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)

Case 2. Here the triplets are:
(1, 3, 2)
(2, 3, 1)

Case 3. 613536 triplets exist

Case 4. Here the only triplet is (1, 2, 3).

Case 5. The only choice for N1 and for is N2 is 1, so any such triple will have the same numbers which does not satisfy the conditions. Hence, no triplets are possible.

SAMPLE INPUT
5
3 3 3
2 3 2
29 11 1994
1 2 3
1 1 50

SAMPLE OUTPUT
6
2
613536
1
0


import sys
i=0
t= eval(input())
t= int(t)
while i<t:
	a,b,c= list(map(int,sys.stdin.readline().split()))
	if a > b and a > c:
		if b > c:
		   temp= a
		   a=c
		   c=temp
		else:
		   temp= a
		   a=b
		   b=temp
		   temp1=c
		   c=b
		   b=temp1

	if b > a and b > c:
		if a > c:
		   temp= a
		   a=c
		   c=temp
		   temp1=c
		   c=b
		   b=temp1
		else:
		   temp=c
		   c=b
		   b=temp
	if c > a and c > b:
		if a > b:
		   temp=b
		   b=a
		   a=temp
	b=b-1
	c=c-2
	tog = int((a*b*c)%1000000007)
	print (tog)
	
	i=i+1


for _ in range(eval(input())):
	a = list(map(int,input().split()))
	a.sort()
	print(((a[2]-1)*(a[1]-1)*a[0] - (a[1]-1)*a[0])%(10**9+7))


t = eval(input())
for xx in range(0,t):
	a,b,c = list(map(int,input().split()))
	ans = a*b*c
	x = min(a,b,c)
	ans -= x
	x = min(a,b)
	y = min(x,c)
	ans -= (y*(c-1))
	ans -= ((x-y)*c)
	x = min(a,c)
	y = min(x,b)
	ans -= (y*(b-1))
	ans -= ((x-y)*b)
	x = min(b,c)
	y = min(x,a)
	ans -= (y*(a-1))
	ans -= ((x-y)*a)
	print(ans%1000000007)


T = int(input())
for i in range(0,T):
	S = list(map(int,input().split()))
	S.sort()
	ans = S[0]*(S[1]-1)*(S[2]-2)
	print(ans%1000000007)


for _ in range(int(input())):
	a = sorted(map(int, input().split()))
	ans = a[0]
	for i in range(1, 3):
		a[i] -= i
		if a[i] < 1:
			ans = 0
		ans *= a[i]
	print(ans % 1000000007)


t=int(input())

for i in range(t):
	n= list(map(int, input().split()))
	n=sorted(n)
	print((n[0]*(n[1]-1)*(n[2]-2))%1000000007)


for t in range(int(input())):
	temp = input().strip().split(' ')

	for i in range(3):
		temp[i] = int(temp[i])

	temp.sort()
	
	print((((temp[0]*(temp[1]-1))%1000000007)*(temp[2]-2))%1000000007)


test=eval(input())
while(test>0):
	A=[]
	[m,n,o] = [int(i) for i in input().split()]
	A.append(m)
	A.append(n)
	A.append(o)
	A.sort()
	res=(A[0]*(A[1]-1)*(A[2]-2))
	print(res%1000000007) 
	test-=1


tc=int(input())
for case in range(tc):
	a=list(map(int,input().split()))
	a.sort(reverse=True)
	m=a[2]
	b=[a[0]-m,a[1]-m,a[2]-m]
	m2=b[1]
	ans=m*(m-1)*(a[1]-2)
	ans=ans+m*m2*(m+m2-2)
	ans=ans+m*(m+m2-1)*(a[0]-m-m2)
	print(ans%1000000007)
	
	


from sys import stdin
a = stdin.readline()
a=stdin.readlines()
for i in a:

	b = i.strip().split()
	c = []
	for j in b:
		c.append(int(j))
	c.sort()
	x=c[0] * (c[1]-1) * (c[2]-2)
	print(x%(10**9+7))


def min(a,b):
	if a<b:
		return a
	else:
		return b
mod=1000000007
t=int(eval(input()))
while t:
	x=input().split(' ')
	a=int(x[0])
	b=int(x[1])
	c=int(x[2])
	f=0
	if a<=1:
		f=f+1
	if b<=1:
		f=f+1
	if c<=1:
		f=f+1
	ans=0
	if f>1:
		ans=0
	else:
		ans=a*b*c
		ans=ans+2*min(a,min(b,c))
		ans=ans-c*min(a,b)-a*min(b,c)-b*min(a,c)
		ans=ans%mod
	print(ans)
	t=t-1


mod=1000000007
for _ in range(int(input())):
	ar=[int(i) for i in input().split()]
	ar.sort()
	
	x,y,z=ar[0],ar[1],ar[2]
	ans=((x%mod)*((y-1)%mod)*((z-2)%mod))%mod
	print(ans)


t=eval(input())
while(t>0):
	lst=[]
	[a,b,c] = [int(i) for i in input().split()]
	lst.append(a)
	lst.append(b)
	lst.append(c)
	lst.sort()
	r=(lst[0]*(lst[1]-1)*(lst[2]-2))
	print(r%1000000007) 
	t-=1