#include #include #include using namespace std; using namespace __gnu_pbds; #define int long long #define REP(i,n) for(int i = 0;i < (int)(n);i++) #define RREP(i,n) for(int i = (int)n-1;i >= 0;i--) #define FOR(i,s,n) for(int i = s;i < (int)n;i++) #define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--) #define ALL(a) a.begin(),a.end() #define IN(a, x, b) (a<=x && xinline bool CHMAX(T&a,T b){if(ainline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;} templateistream&operator >>(istream&is,vector&vec){for(T&x:vec)is>>x;return is;} templateinline void in(T&t){cin>>t;} templateinline void in(T&t,Ts&...ts){cin>>t;in(ts...);} templateinline void out(T t){cout<inline void out(T t,Ts... ts){cout<vectormv(size_t a){return vector(a);} templateauto mv(size_t a,Ts... ts){return vector(ts...))>(a,mv(ts...));} templatetypename enable_if::value==0>::type fill(T&t,const V&v){t=v;} templatetypename enable_if::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);} constexpr long long INF = 1e18; signed main(){ int Q; in(Q); vectorans; while(Q--){ int ret = INF; auto a = mv(3); in(a); int flg; auto f = [&](int i,int j,int k){ int ret = 0; int top = a[i]; int middle = min(a[i]-1,a[j]); int bottom = min(middle-1,a[k]); if(bottom <= 0)flg = 0; return abs(a[j]-middle)+abs(a[k]-bottom); }; REP(i,3){ REP(j,3){ REP(k,3){ if(i == j)continue; if(j == k)continue; if(k == i)continue; if(j == 1)continue; flg = 1; int t = f(i,j,k); if(flg)CHMIN(ret,t); } } } ans.push_back(ret); } for(auto e:ans){ if(e == INF)out(-1); else out(e); } }