#include "bits/stdc++.h" using namespace std; typedef long long int ll; typedef pair pi; typedef pair, ll > pii; vector vec; vector > vec2; ll MOD = 1000000007; ll INF = 1145141919454519; int main(){ ll T; cin >> T; vector ans; for(ll i = 0; i < T; i++){ ll a, b, c; cin >> a >> b >> c; if(a != c && ((b > a && b > c)||(b < a && b < c))){ //すでに条件を満たしている時 //cout << 0 << endl; ans.push_back(0); }else{ //1が含まれていたら真ん中を最大化するしかない if(a == 1 || c == 1){ if(a==c){ //cout << -1 << endl; ans.push_back(-1); }else if(b <= 2){ //cout << -1 << endl; ans.push_back(-1); }else{ //cout << abs(b - max(a, c)) + 1 << endl; ans.push_back(abs(b - max(a, c)) + 1); } }else{ if(a == b && b == c && a == c){ if(a == 2){ //cout << -1 << endl; ans.push_back(-1); }else{ //cout << 3 << endl; ans.push_back(3); } }else{ //中央を最小化 ll ans1 = INF; ll ans2 = INF; //中央を最大化 ll ans3 = INF; if(abs(a-c) == 2){ ans1 = abs(b-min(a,c))+1; ans3 = 3; }else if(abs(a-c) == 1){ ans1 = abs(b-min(a,c))+1; ans3 = 2; }else if(abs(a-c) == 0){ if(a > b){ if(a == 2){ ans3 = -1; }else{ if(abs(a-b) != 1){ ans3 = 1; }else{ ans3 = 2; } } }else{ ans3 = 1; } }else{ ans1 = abs(b-min(a,c))+1; ans2 = abs(b-max(a,c))+1; } ans.push_back(min(min(ans1, ans2), ans3)); //cout << min(min(ans1, ans2), ans3) << endl; } } } } for(ll i = 0; i < T; i++){ cout << ans[i] << endl; } }