T = int(input()) A = [0]*T B = [0]*T C = [0]*T for i in range(T): A[i], B[i], C[i] = map(int, input().split()) inf = 3*10**9 for i in range(T): if 0 < A[i] < B[i] and 0 < C[i] < B[i] and A[i] != C[i]: print(0) continue if 0 < B[i] and min(A[i], B[i], C[i]) == B[i] and A[i] != C[i] and B[i] != A[i]: print(0) continue a = max(B[i], C[i])-1 if a == min(B[i], C[i]): a -= 1 if a <= 0 or B[i] == C[i] or A[i] == min(A[i], B[i], C[i]): a = inf else: a = A[i]-a b = min(A[i], C[i])-1 if b <= 0 or A[i] == C[i]: b = inf else: b = B[i]-b c = max(A[i], B[i])-1 if c == min(A[i], B[i]): c -= 1 if c <= 0 or A[i] == B[i] or C[i] == min(A[i], B[i], C[i]): c = inf else: c = C[i]-c ans = min(a, b, c) if ans == inf: ans = -1 if A[i] == B[i] and B[i] == C[i] and A[i] > 2: ans = 3 print(ans)