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