#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; ll t_a1, t_b1, t_c1; t_a1 = a; t_b1 = b; t_c1 = c; ll t_a2, t_b2, t_c2; t_a2 = a; t_b2 = b; t_b2 = 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 << 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 = b-min(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; } } } } }