def makekado(x, y, z): ans = 0 maxxyz = max(x, y, z) minxyz = min(x, y, z) if x > z: x, z = z, x if x == y and y == z: if x >= 3: ans = 3 else: ans = -1 elif x == z: if maxxyz == y: if x == 1: ans = -1 else: ans = 1 if minxyz == y: if y == 1: if x == 2: ans = -1 else: ans = 1 else: if y == x - 1: ans = 2 else: ans = 1 else: if maxxyz == y: if y > z: ans = 0 else: if y < 3: ans = -1 else: if y - x == 1: ans = 2 else: ans = -1 elif minxyz == y: if y < x: ans = 0 else: if x == 1: ans = -1 else: ans = 1 else: if x == 1: if y == 2: ans = -1 else: ans = z - y + 1 else: if y == x + 1: ans = 2 else: ans = min(y - x, z - y) + 1 print(ans) return n = int(input()) for i in range(n): a, b, c = [ int(v) for v in input().split() ] makekado(a, b, c)