#!/usr/bin/env python3 import math def iterate(a, b, c): for a in range(a - 3, a + 1): for b in range(b - 3, b + 1): for c in range(c - 3, c + 1): yield a, b, c yield min(b - 1, a), b, min(b - 2, c) yield min(b - 2, a), b, min(b - 1, c) yield a, min(a - 1, b), c yield a, min(c - 1, b), c def solve(a, b, c): ans = math.inf for a1, b1, c1 in iterate(a, b, c): if 1 <= a1 and 1 <= b1 and 1 <= c1: if a1 != c1 and ((a1 < b1 and b1 > c1) or (a1 > b1 and b1 < c1)): ans = min(ans, a - a1 + b - b1 + c - c1) if math.isinf(ans): return -1 return ans for _ in range(int(input())): a, b, c = map(int, input().split()) print(solve(a, b, c))