def main(): queries = int(input()) for _ in range(queries): a, b, c = map(int, input().split()) if a == b == c: print(3) elif a == b < c or a > b == c: print(1) elif a == b > c or a < b == c: if b == c + 1 or a + 1 == b: print(2) else: print(1) elif a < b < c or c < b < a: diff = min(abs(b - a), abs(c - b)) + 1 b -= diff print(diff if b > 0 else -1) elif max(a, b, c) == b or min(a, b, c) == b: print(0) if __name__ == '__main__': main()