This is probably the simplest problem ever. You just need to count the number of ordered triples of different numbers (X1, X2, X3), where Xi could be any positive integer from 1 to Ni, inclusive (i = 1, 2, 3).
No, wait. I forgot to mention that numbers N1, N2, N3 could be up to 1018. Well, in any case it is still quite simple :)
By the way, because of this the answer could be quite large. Hence you should output it modulo 109 + 7. That is you need to find the remainder of the division of the number of required triples by 109 + 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. The only line of each 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 109 + 7.

-----Constraints-----
- 1 ≤ T ≤ 1000
- 1 ≤ Ni ≤ 1018

-----Example-----
Input:
5
3 3 3
2 4 2
1 2 3
25 12 2012
1 1 2013

Output:
6
4
1
578880
0

-----Explanation-----
Example 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)
Example case 2. Here the triples are:
(1, 3, 2)
(1, 4, 2)
(2, 3, 1)
(2, 4, 1)
Example case 3. Here the only triple is (1, 2, 3).
Example case 4. Merry Christmas! 
Example case 5. ... and Happy New Year! By the way here the answer is zero since the only choice for X1 and for is X2 is 1, so any such triple will have equal numbers.

Source: codechef | Difficulty: MEDIUM
Tags: Combinatorics

Mathematics


Solutions:
mo = 1000000007
for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	print(l[0] * ((l[1] - 1) % mo) * ((l[2] - 2) % mo) % mo)


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


m = 1000000007
for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] >= 1 and l[1] > 1 and (l[2] > 2):
		print(l[0] * (l[1] - 1) * (l[2] - 2) % m)
	else:
		print(0)


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


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	l.sort()
	m = 10 ** 9 + 7
	p = l[0] % m
	q = (l[1] - 1) % m
	r = (l[2] - 2) % m
	s = p * q * r % m
	if l[0] == 1 and l[1] == 1:
		print(0)
	else:
		print(s)


try:
	for i in range(int(input())):
		l = list(map(int, input().split()))
		l.sort()
		m = 1
		a = l[0]
		b = l[1]
		c = l[2]
		ans = a * (b - 1) * (c - 2)
		print(ans % (10 ** 9 + 7))
except:
	pass


t = int(input())
while t > 0:
	x = list(map(int, input().split()))
	x.sort()
	ans = x[0] * (x[1] - 1) * (x[2] - 2)
	ans = ans % (10 ** 9 + 7)
	print(ans)
	t = t - 1


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


try:
	t = int(input())
	for jdnkjdew in range(t):
		arr = list(map(int, input().split()))
		arr.sort()
		a = arr[0] * (arr[1] - 1) * (arr[2] - 2)
		a %= 1000000007
		print(a)
except:
	pass


mod = 10 ** 9 + 7
for test in range(int(input())):
	l = sorted(map(int, input().split()))
	print(l[0] * (l[1] - 1) * (l[2] - 2) % mod)


tc = int(input())
for _ in range(tc):
	A = list(map(int, input().split()))
	A.sort()
	print(A[0] * (A[1] - 1) % 1000000007 * (A[2] - 2) % 1000000007)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	l = [x, y, z]
	l.sort()
	a = l[0]
	b = l[1] - 1
	c = l[2] - 2
	if a * b * c < 0:
		print(0)
	else:
		print(a * b * c % (10 ** 9 + 7))


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


d = 1000000007
for _ in range(int(input())):
	l = sorted(list(map(int, input().split())))
	ans = l[0] % d * ((l[1] - 1) % d) * ((l[2] - 2) % d)
	print(ans % d)


for _ in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	ans = a * (b - 1) * (c - 2)
	print(ans % (10 ** 9 + 7) if ans > 0 else 0)


for _ in range(int(input())):
	n = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	n.sort()
	t_1 = n[0]
	for i in range(1, 3):
		t_1 %= mod
		t_1 *= n[i] - i
	print(t_1 % mod)


T = int(input())
for i in range(T):
	inp = [int(x) for x in input().split()]
	inp = sorted(inp)
	inp[1] = inp[1] - 1
	inp[2] = inp[2] - 2
	if inp[1] <= 0 or inp[2] <= 0:
		print('0')
	else:
		ans = inp[0] * inp[1] % 1000000007 * inp[2] % 1000000007
		print(ans % 1000000007)


test = int(input())
for _ in range(test):
	array = list(map(int, input().split()))
	array.sort()
	mod = 1000000007
	answer = array[0] * (array[1] - 1) * (array[2] - 2)
	if answer <= 0:
		print(0)
	else:
		print(answer % mod)


def soln(abc):
	mod = 10 ** 9 + 7
	(a, b, c) = sorted(abc)
	res = a * (b - 1) % mod
	res = res * (c - 2) % mod
	return res
for _ in range(int(input())):
	abc = list(map(int, input().split()))
	print(soln(abc))


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


t = int(input())
for i in range(t):
	A = list(map(int, input().split()))
	M = 10 ** 9 + 7
	A.sort()
	ans = A[0] % M * ((A[1] - 1) % M) % M
	ans = ans % M * ((A[2] - 2) % M) % M
	print(ans)


t = int(input())
for tc in range(t):
	array = sorted(list(map(int, input().split())))
	ans = array[0] * (array[1] - 1) * (array[2] - 2) % (10 ** 9 + 7)
	print(ans)


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


for _ in range(int(input())):
	a = [int(x) for x in input().split()]
	p = 1
	d = 0
	a.sort()
	mod = 10 ** 9 + 7
	for v in a:
		p = p * (v - d) % mod
		d += 1
	print(p % mod)


for __ in range(int(input())):
	n = list(map(int, input().split()))
	n.sort()
	ans = 1
	for i in range(3):
		ans *= n[i] - i
	print(ans % (10 ** 9 + 7))


for _ in range(int(input())):
	r = [int(x) for x in input().split()]
	(a, b, c) = sorted(r)
	print(a * (b - 1) * (c - 2) % 1000000007)


mod = 10 ** 9 + 7

def solve():
	arr = list(map(int, input().split()))
	arr.sort()
	ans = 1
	a = arr[0]
	a %= mod
	a *= arr[1] - 1
	a %= mod
	a *= arr[2] - 2
	a %= mod
	print(a)
t = int(input())
while t != 0:
	solve()
	t -= 1


T = int(input())
ans = []
m = 10 ** 9 + 7
for _ in range(T):
	N = [int(i) for i in input().split()]
	N.sort()
	ans.append(N[0] % m * ((N[1] - 1) % m) * ((N[2] - 2) % m) % m)
for i in ans:
	print(i)


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


mod = 1000000007
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	li = sorted([a, b, c])
	(a2, b2, c2) = (li[0], li[1], li[2])
	ans = a2 * (b2 - 1) % mod
	ans2 = ans * (c2 - 2) % mod
	print(ans2)


mod = 1000000007
for _ in range(int(input())):
	arr = list(map(int, input().split()))
	arr.sort()
	print(arr[0] * (arr[1] - 1) * (arr[2] - 2) % mod)


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


m = 10 ** 9 + 7
for _ in range(int(input())):
	(n1, n2, n3) = map(int, input().split())
	ls = [n1, n2, n3]
	ls.sort()
	print(ls[0] * (ls[1] - 1) * (ls[2] - 2) % m)


t = int(input())
while t != 0:
	a = [int(i) for i in input().split()]
	a.sort()
	print(a[0] * (a[1] - 1) * (a[2] - 2) % int(1000000000.0 + 7))
	t = t - 1


for _ in range(int(input())):
	a = []
	a = [int(i) for i in input().split()]
	a.sort()
	print(a[0] * (a[1] - 1) * (a[2] - 2) % 1000000007)


from functools import reduce
m = 10 ** 9 + 7
t = int(input())
while t > 0:
	lst = list(map(int, input().split()))
	lst.sort()
	lst[2] = lst[2] - 2
	lst[1] = lst[1] - 1
	ans = reduce(lambda x, y: x * y, lst)
	print(ans % m)
	t -= 1


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


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


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


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


for _ in range(int(input())):
	N = list(map(int, input().split()))
	N.sort()
	(N1, N2, N3) = (N[0], N[1], N[2])
	M = 10 ** 9 + 7
	ans = N1 % M * ((N2 - 1) % M) % M * (N3 - 2) % M % M
	print(ans)


for _ in range(int(input())):
	li1 = [int(x) for x in input().split()]
	li1 = sorted(li1)
	li1[1] = li1[1] - 1
	li1[2] = li1[2] - 2
	if li1[1] <= 0 or li1[2] <= 0:
		print('0')
	else:
		ans = li1[0] * li1[1] % 1000000007 * li1[2] % 1000000007
		print(ans % 1000000007)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	m = 10 ** 9 + 7
	l.sort()
	ans = 1
	for j in range(3):
		ans *= l[j] - j
	print(ans % m)


t = int(input())
for _ in range(t):
	list1 = list(map(int, input().strip().split()))
	list1.sort()
	ans = 1
	m = 10 ** 9 + 7
	for i in range(3):
		ans = ans * (list1[i] - i) % m
	print(ans)


for _ in range(int(input())):
	pairs = sorted(list(map(int, input().split())))
	ans = 1
	for i in range(len(pairs)):
		ans *= pairs[i] - i
	print(ans % (10 ** 9 + 7))


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


T = int(input())
for _ in range(T):
	v = list(map(int, input().split()))
	v.sort()
	print(v[0] * (v[1] - 1) * (v[2] - 2) % int(1000000000.0 + 7))


from math import *
import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	n = 3
	ans = l[0]
	for i in range(1, n):
		ans = ans * (l[i] - i)
		ans = ans % mod
	print(ans)


for _ in range(int(input())):
	(N1, N2, N3) = map(int, input().split())
	z = []
	z.append(N1)
	z.append(N2)
	z.append(N3)
	A = sorted(z)
	a = A[0]
	b = A[1]
	c = A[2]
	d = a * (b - 1) * (c - 2) % 1000000007
	print(d)


def fun(a, b, c, p):
	if min(a, b) <= c:
		return min(a, b) * (c - 1) % p
	return (min(a, b) - 1) * c % p
t = int(input())
while t > 0:
	(N1, N2, N3) = input().split()
	P = 1000000007
	N1 = int(N1)
	N2 = int(N2)
	N3 = int(N3)
	print((P + N1 % P * (N2 % P) % P * (N3 % P) % P - min(N1, min(N2, N3)) % P - (P + fun(N1, N2, N3, P)) % P - (P + fun(N2, N3, N1, P)) % P - (P + fun(N1, N3, N2, P)) % P) % P)
	t = t - 1


tests = int(input())
for i in range(tests):
	arr = list(map(int, input().split()))
	arr.sort()
	mod = 10 ** 9 + 7
	(a2, b2, c2) = (arr[0], arr[1], arr[2])
	ans = a2 * (b2 - 1) % mod
	ans = ans * (c2 - 2) % mod
	print(ans)


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


for i in range(int(input())):
	l = list(map(int, input().split()))
	a = min(l)
	b = max(l)
	sum = 0
	for i in l:
		sum += i
	c = sum - a - b
	x = a * (c - 1) * (b - 2)
	y = x % (7 + 10 ** 9)
	print(y)


t = int(input())
for i in range(t):
	a = [int(x) for x in input().split()]
	a = sorted(a)
	a[1] = a[1] - 1
	a[2] = a[2] - 2
	if a[1] <= 0 or a[2] <= 0:
		print('0')
	else:
		an = a[0] * a[1] % 1000000007 * a[2] % 1000000007
		print(an % 1000000007)


T = int(input())
for _ in range(T):
	array = list(map(int, input().strip().split()))
	array.sort()
	x1 = array[0]
	x2 = array[1]
	x3 = array[2]
	result = x1 * (x2 - 1) * (x3 - 2) % (10 ** 9 + 7)
	print(result)


for _ in range(int(input())):
	arr = [int(a) for a in input().split()]
	arr.sort()
	ans = 1
	mod = 10 ** 9 + 7
	for l in range(3):
		ans = ans * ((arr[l] - l) % mod)
	print(ans % mod)


MOD = 10 ** 9 + 7
for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	(a, b, c) = l
	res = a % MOD * ((b - 1) % MOD) * ((c - 2) % MOD) % MOD
	print(res)


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


for _ in range(int(input())):
	lst = list(map(int, input().split()))
	lst.sort()
	a = lst[0]
	b = lst[1]
	c = lst[2]
	count = a * (b - 1) * (c - 2)
	print(count % 1000000007)


for _ in range(int(input())):
	some = list(map(int, input().split()))
	some = sorted(some)
	some[1] = some[1] - 1
	some[2] = some[2] - 2
	if some[1] == 0 or some[2] == 0:
		print(0)
	else:
		print(some[0] * some[1] * some[2] % 1000000007)


import sys
input = sys.stdin.readline

def rii():
	return range(int(input().strip()))

def ii():
	return int(input().strip())

def mii():
	return map(int, input().strip().split(' '))

def lmii():
	return list(map(int, input().strip().split(' ')))

def si():
	return str(input().strip())
mod = 10 ** 9 + 7

def solve(*args):
	(n1, n2, n3) = sorted(args)
	return n1 * (n2 - 1) * max(0, n3 - 2) % mod

def do_codechef():
	for t in rii():
		print(solve(*lmii()))
do_codechef()
exit()


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


for _ in range(int(input())):
	li = list(map(int, input().split()))
	m = 10 ** 9 + 7
	li.sort()
	ans = 1
	for i in range(3):
		ans = ans * (li[i] - i)
	print(ans % m)