from collections import deque N = int(input()) for n in range(N): a, b, c = map(int, input().split()) if c > a: a, c = c, a if a == b == c and a >= 3: print(3) elif b > a > c or a > c > b: print(0) elif a > b and b == c and b >= 2: print(1) elif a == b and b > c: if b > c + 1: print(1) elif b == c + 1 and c >= 2: print(2) elif a == c and b > a and a >= 2: print(1) elif a == c and b < a: if a > b + 1: print(1) if a == b + 1 and b >= 2: print(2) elif (not a == b and not b == c and not c == a) and (c >= 2 or c == 1 and b > c + 1): t = 10000000000 if c >= 2: t = min(t, b - c + 1) if b > c + 1: t = min(t, a - b + 1) if t == 10000000000: print(-1) else: print(t) else: print(-1)