MOD = 10 ** 9 + 7 INF = 10 ** 12 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) from itertools import permutations def main(): t = int(input()) for _ in range(t): a,b,c = map(int,input().split()) ans = INF if b < c: if b < a < c: ans = 0 elif a <= b: if a > 1: ans = min(ans,b - a + 1) elif c <= a: if b + 1 == c: if b > 1: ans = min(ans,a - c + 2) else: ans = min(ans,a - c + 1) elif c < b: if c < a < b: ans = 0 elif a <= c: if a > 1: ans = min(ans,c - a + 1) elif b <= a: if c + 1 == b: if c > 1: ans = min(ans,a - b + 2) else: ans = min(ans,a - b + 1) elif b == c: if a == b: if a > 2: ans = min(ans,3) elif a > b: if b > 2: ans = min(ans,a - b + 3) else: if a > 1: ans = min(ans,b - a + 1) if a < b: if a < c < b: ans = 0 elif c <= a: if c > 1: ans = min(ans,a - c + 1) elif b <= c: if a + 1 == b: if a > 1: ans = min(ans,c - b + 2) else: ans = min(ans,c - b + 1) elif b < a: if b < c < a: ans = 0 elif c <= b: if c > 1: ans = min(ans,b - c + 1) elif a <= c: if b + 1 == a: if b > 1: ans = min(ans,c - a + 2) else: ans = min(ans,c - a + 1) elif a == b: if c == b: if a > 2: ans = min(ans,3) elif c < a: if c > 1: ans = min(ans,a - c + 1) else: if a > 2: ans = min(ans,c - b + 3) if ans == INF: print(-1) else: print(ans) if __name__ =='__main__': main()