t = int(input()) INF = 10**18 for i in range(t): a, b, c = map(int, input().split()) base = 0 if a == c: if a == 1: base = INF else: a -= 1 base = 1 if a > c: a, c = c, a ans1 = base if a < b and c < b: pass else: if b >= 3: if a >= b-2: ans1 += a-(b-2) if c >= b-1: ans1 += c-(b-1) else: ans1 = INF ans2 = base if b < a and b < c: ans2 = 0 else: if a >= 2: ans2 += b-(a-1) else: ans2 = INF ans = min(ans1, ans2) if ans < INF: print(ans) else: print(-1)