import sys input = sys.stdin.readline def main(): T = int(input()) for _ in range(T): ans = 0 A, B, C = map(int, input().split()) if A == C == 1: print(-1) continue if B <= 2: max_cost = float('inf') else: max_cost = 0 if A >= B: max_cost += A - (B - 1) if C >= B: max_cost += C - (B - 1) if A == C: max_cost += 1 if A == 1 or C == 1 or A == C == 2: min_cost = float('inf') else: min_cost = 0 if A == C: min_cost += 1 C -= 1 min_cost += max(B - (min(A,C) - 1),0) ans = min(max_cost, min_cost) if ans == float('inf'): print(-1) else: print(ans) if __name__ == "__main__": main()