#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; 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; }else{ //1が含まれていたら真ん中を最大化するしかない if(a == 1 || c == 1){ if(a==c){ cout << -1 << endl; }else if(b <= 2){ cout << -1 << endl; }else{ cout << abs(b - max(a, c)) + 1 << endl; } }else{ if(a == b && b == c && a == c){ if(a == 2){ cout << -1 << endl; }else{ cout << 3 << endl; } }else{ //中央を最小化 ll ans1 = abs(b-max(a,c))+1; //中央を最大化 ll ans2 = INF; if(abs(a-c) == 2){ ans2 = 3; }else if(abs(a-c) == 1){ ans2 = 2; }else if(abs(a-c) == 0){ ans2 = 1; } cout << min(ans1, ans2) << endl; } } } } }