Ichigo is receiving special training from Kisuke Urahara to beat Aizen. This time, Kisuke took (P * Q * R) identical cubes and made them into a big box of dimensions P x Q x R. Moreover, it happened quite by chance that P, Q, R were all pairwise coprime, that is, gcd(P, Q) = gcd(Q, R) = gcd(R, P) = 1 where gcd(X, Y) is the greatest integer dividing both X and Y. He then asked Ichigo to cut the box into two pieces with a single slice. Ichigo used a Getsuga Tenshou in his hollow form on the box and sliced it into two parts completely. 

His slice was such that for a corner vertex X of the box, if A, B, C are the vertices of the box adjacent to X, then Ichigo's slice was a plane passing through A, B, C as given in the picture below. Now Kisuke is wondering what is the number of cubes that were cut into two parts. Since the answer can be huge, output it modulo (10^{9} + 7).

Input Format:

Line 1: T 

T - Number of test cases. 

Lines 2 to T+1: P Q R 

P, Q, R - the dimensions of the box  

Output Format:

For each test case, print a single integer in a new line that is the number of cubes that were cut by Ichigo modulo (10^{9} + 7).

Constraints:

1 <= T <= 1000 

1 <= P, Q, R <= 10^{12} 

P, Q, R are pairwise coprime

Sample Input:

3
1 1 1
2 1 3
5 3 2

Sample Output:

1
5
15

Explanation:

In the first test case, we have a single cube. And when Ichigo slices it, that single cube is sliced. So, the answer is 1.

In the second test case, we have a (2 x 1 x 3) cuboid. Then, when Ichigo takes an arbitrary vertex X and slice the cuboid as explained, then the cube which contains the vertex diagonally(body diagonal) opposite X in the cuboid is not cut, every other cube is cut. So, 5 cubes are cut.

Difficulty: MEDIUM
Tags: Number theory

Starter code:

Solutions:
T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


from math import ceil
for _ in range(int(input())):
	(p, q, r) = map(int, input().split())
	print((p * q + p * r + q * r - 1) // 2 % 1000000007)


md = 10 ** 9 + 7

def h(a, b):
	return (a * b - (a * b - a - b + 1) // 2) % md
t = int(input())
for i in range(t):
	(p, q, r) = map(int, input().split())
	print((h(p, q) + h(p, r) + h(q, r) - p - q - r + 1) % md)


mod = 10 ** 9 + 7
for _ in range(int(input())):
	(a, b, c) = [int(x) for x in input().split()]
	print((a * b + b * c + c * a - 1) // 2 % mod)


from math import ceil
for _ in range(int(input())):
	(p, q, r) = map(int, input().split())
	print((p * q + p * r + q * r - 1) // 2 % 1000000007)


MOD = 1000000007
t = int(input())
for _ in range(t):
	(p, q, r) = list(map(int, input().split()))
	print((p * q + q * r + r * p >> 1) % MOD)


import os, sys, math

def solve(p, q, r):
	MOD = 10 ** 9 + 7
	return (p * q + p * r + q * r - 1) // 2 % MOD

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		(p, q, r) = list(map(int, sys.stdin.readline().split()))
		print(solve(p, q, r))
main()


import os, sys, math
MOD = 10 ** 9 + 7

def solve(p, q, r):
	return (p * q + q * r + p * r - 1) // 2 % MOD
T = int(input())
for t in range(T):
	(p, q, r) = [int(s) for s in input().split()]
	print(solve(p, q, r))


def hacker_cube_submit():
	m = 10 ** 9 + 7
	q = int(input())
	for q_itr in range(q):
		(p, q, r) = list(map(int, input().split()))
		print((p * q + p * r + q * r - 1) // 2 % m)
hacker_cube_submit()


from math import ceil
for _ in range(int(input())):
	(p, q, r) = map(int, input().split())
	print((p * q + p * r + q * r - 1) // 2 % 1000000007)


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


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


for _ in range(int(input())):
	(P, Q, R) = list(map(int, input().split()))
	print((P * Q + P * R + Q * R) // 2 % (pow(10, 9) + 7))


def ichigo(P, Q, R, M):
	return (P * Q + Q * R + P * R - 1) // 2 % M
M = int(1000000000.0 + 7)
numTests = int(input().strip())
for _ in range(numTests):
	(P, Q, R) = list(map(int, input().rstrip().split()))
	result = ichigo(P, Q, R, M)
	print(result)


t = int(input())
for _ in range(t):
	[p, q, r] = list(map(int, input().split(' ')))
	print((p * q + p * r + q * r - 1) // 2 % 1000000007)


T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


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


T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


T = int(input())
for t in range(T):
	(P, Q, R) = [int(_) for _ in input().split(' ')]
	print((P * Q + Q * R + R * P >> 1) % (10 ** 9 + 7))


mod = 10 ** 9 + 7

def solve(n, m, r):
	result = (n - 1) * (m - 1) // 2
	result += (n - 1) * (r - 1) // 2
	result += (r - 1) * (m - 1) // 2
	result += n - 1 + (m - 1) + (r - 1) + 1
	return result % mod
for _ in range(int(input())):
	(n, m, r) = map(int, input().split())
	print(solve(n, m, r))


def solve(p, q, r):
	return (p * q + q * r + r * p - 1) // 2 % (10 ** 9 + 7)
n = int(input())
for i in range(n):
	pqr = list(map(int, input().strip().split(' ')))
	(p, q, r) = (pqr[0], pqr[1], pqr[2])
	print(solve(p, q, r))


t = int(input())
for i in range(t):
	(p, q, r) = input().strip().split()
	p_m = int(p)
	q_m = int(q)
	r_m = int(r)
	ans = int((p_m * q_m + q_m * r_m + r_m * p_m - 1) // 2)
	print(int(ans % 1000000007))