#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } ll func(int x, int y, int z){ ll res = 0; if(y >= z){ res += y - z + 1; y = z - 1; } if(x >= y){ res += x - y + 1; x = y - 1; } if(x <= 0) res = 1e+17; return res; } void solve(){ int A, B, C; cin >> A >> B >> C; ll ans = 1e+17; chmin(ans, func(B, A, C)); chmin(ans, func(C, A, B)); chmin(ans, func(A, C, B)); chmin(ans, func(B, C, A)); if(ans == 1e+17) ans = -1; cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--) solve(); return 0; }