#include using namespace std; #define int long long int solve(int a, int b, int c){ int ans = 0; if(a <= b){ if(a == 1) return LLONG_MAX; ans += b-(a-1); b = a-1; } if(b <= c){ if(b == 1) return LLONG_MAX; ans += c-(b-1); } return ans; } signed main(){ int t; cin >> t; for(int i = 0;i < t;i++){ int a, b, c; cin >> a >> b >> c; int ans = min({solve(b, a, c), solve(b, c, a), solve(a, c, b), solve(c, a, b)}); if(ans == LLONG_MAX){ cout << -1 << endl; }else{ cout << ans << endl; } } return 0; }