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 and c >= 2: print(2) elif a == c and b > a and a >= 2: print(1) elif a == c and b < a and b >= 2: print(2) elif c >= 2: print(b - c + 1) else: print(-1)