t = int(input()) for tt in range(t): a = list(map(int, input().split())) ans = 10**18 for i, j, k in [(0, 2, 1), (1, 2, 0) ,(1, 0, 2), (2, 0, 1)]: tmp1 = max(a[j] - a[i] + 1, 0) aj = a[j] - tmp1 tmp2 = max(a[k] - aj + 1, 0) ak = a[k] - tmp2 if ak > 0: ans = min(ans, tmp1 * a[j + 3] + tmp2 * a[k + 3]) if ans == 10**18: print(-1) else: print(ans)