#include #define rep(i,n) for(int i=0;i pp; const int INF = 1e9; const int MOD = 1000000007; int main() { int t; cin >> t; auto f = [](int cen,int l,int r){ int res = 0; if( l > r) swap(l,r); if(l == r && r == cen){ l -= 2; cen --; res += 3; } if(l == r){ l -= 2; res += 2; } if(l == r-1){ l --; res += 1; } if( r <= cen){ res += cen - r + 1; cen = r -1; } if( cen <= l){ res += l - cen + 1; l = cen - 1; } if( cen <= 0 || l <= 0 || r <= 0){ return -1; }else{ return res; } }; rep(i,t){ int a,b,c; cin >> a >> b >> c; int res_a = f(a,b,c); int res_b = f(c,a,b); if(res_a == -1 && res_b == -1) cout << -1 << endl; else if(res_a == -1) cout << res_b << endl; else if(res_b == -1) cout << res_a << endl; else cout << min(res_a,res_b) << endl; } return 0; }