t = int(input()) for i in range(t): a, b, c = map(int, input().split()) l = [a, b, c] if len(set(l)) == 1: if a == 1 or a == 2: print(-1) else: print(3) elif len(set(l)) == 2: print(0) else: l.sort(reverse=True) if a == l[0] and b == l[1] and c == l[2]: ans1 = a-b+1 if b-1 == c: if c == 1: ans1 = -1 else: ans1 += 1 ans2 = b-c+1 if c == 1: ans2 = -1 if ans1 == -1 and ans2 == -1: print(-1) else: print(min(ans1, ans2)) elif a == l[0] and b == l[2] and c == l[1]: print(0) elif a == l[1] and b == l[0] and c == l[2]: print(0) elif a == l[1] and b == l[2] and c == l[0]: print(0) elif a == l[2] and b == l[0] and c == l[1]: print(0) else: a, c = c, a ans1 = a-b+1 if b-1 == c: if c == 1: ans1 = -1 else: ans1 += 1 ans2 = b-c+1 if c == 1: ans2 = -1 if ans1 == -1 and ans2 == -1: print(-1) else: print(min(ans1, ans2))