T = int(input()) abclst = [list(map(int, input().split())) for _ in range(T)] for i in range(T): maxt = max(abclst[i]) mint = min(abclst[i]) midt = 0 ans = -1 if abclst[i].count(abclst[i][0]) == 3: if abclst[i][0] >= 3: print(3) else: print(-1) continue for j in range(3): if abclst[i][j] != maxt and abclst[i][j] != mint: midt = abclst[i][j] if j == 0 or j == 2: ans = 0 break if ans == 0: print(ans) else: tmp1 = maxt - midt + 1 if maxt - tmp1 == mint: tmp1 += 1 if maxt - tmp1 > 0: ans = tmp1 tmp2 = midt - mint + 1 if midt - mint > 0: ans = min(ans, tmp2) print(-1)