#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=b-1LL;i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define endl "\n" #define print(x) cout<<#x<<" = "<=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){ return -1; } else{ return mn; } } int main(){ int T; cin>>T; for(int t = 0; t < T; t++){ int a,b,c; cin>>a>>b>>c; cout << f(a,b,c) << endl; } return 0; }