#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; REP(it, T){ int a,b,c; cin >> a >> b >> c; ll oa = a, ob = b, oc = c; if((a < b && b < c) || (c < b && b < a)){ if(a == c){ b--; c--;c--; }else if(a > c){ a -= ((a-b)+1); if(a == c) c--; }else{ c -= ((c-b)+1); if(a == c) c--; } if(a < 1 || b < 1 || c < 1) pr(-1); else pr((oa-a)+(ob-b)+(oc-c)); }else{ pr(0); } } }