#include #include #include #include #include #include #include #include using namespace std; const int INF = 1001001001; int A , B , C; int check (int a , int b , int c) { return (a != b && b != c && c != a && (b > a && b > c || b < a && b < c) && a > 0 && b > 0 && c > 0); } int solve2 (int a , int b , int c) { int ret = 0; if (a == c) c -= 1; if (a >= b) a -= (a - b + 1); if (c >= b) c -= (c - b + 1); if (check(a , b , c) == true) { return abs(A - a) + abs(B - b) + abs(C - c); } else { return INF; } } int solve3 (int a , int b , int c) { if (b >= a) b -= (b - a + 1); if (b >= c) b -= (b - c + 1); if (a == c) a -= 1; if (b >= a) b -= (b - a + 1); if (b >= c) b -= (b - c + 1); if (check(a , b , c) == true) { return abs(A - a) + abs(B - b) + abs(C - c); } else { return INF; } } void solve() { cin >> A >> B >> C; int cost1 = solve2 (A , B , C); int cost2 = solve3 (A , B , C); int cost = min(cost1 , cost2); if (cost == INF) cost = -1; cout << cost << endl; return; } int main() { int t; cin >> t; for (int i = 0; i < t; i++) { solve(); } return 0; }