#include #define PI 3.14159265358979323846 #define MAXINF (1e18L) #define INF (1e9L) #define EPS (1e-9) #define MOD ((ll)(1e9+7)) #define REP(i, n) for(int i=0;i=0;--i) #define ALL(v) v.begin(),v.end() #define FIND(v,x) (binary_search(ALL(v),(x))) #define SORT(v) sort(ALL(v)) #define RSORT(v) sort(ALL(v));reverse(ALL(v)) #define DEBUG(x) cerr<<#x<<": "<void pr(A a){cout << (a) << endl;} templatevoid pr(A a,B b){cout << a << " " ;pr(b);} templatevoid pr(A a,B b,C c){cout << a << " " ;pr(b,c);} templatevoid pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);} template inline bool chmin(T& a, T b){return a>b ? a=b, true : false;} template inline bool chmax(T& a, T b){return a pii; typedef pair pll; int main(void) { int T; cin >> T; vector ans; auto is_kado = [](ll a, ll b, ll c){ if(a == b || b == c || a == c) return false; vector v = {a,b,c}; SORT(v); return (v[1]== a || v[1] == c); }; REP(it, T){ int a,b,c; cin >> a >> b >> c; int e = 0; if(a==c){ a--; e++; } int mn = 2000000010; if(b>=3&&max(a,c)>=2){ int d = 0; d += max(0,max(a,c)-(b-1)); d += max(0,min(a,c)-(b-2)); mn = min(mn,d+e); } if(max(a,c)>=3&&min(a,c)>=2){ int d = 0; d += max(0,b-(min(a,c)-1)); mn = min(mn,d+e); } if(mn==2000000010){ ans.pb(-1); } else{ ans.pb(mn); } } for(auto&& aa : ans) pr(aa); }