#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(b > a && b > c){ cout << 0 << endl; }else if(b < a && b < c){ cout << 0 << endl; }else{ if((a == 1 || c == 1) && abs(a-c) == 1 ){ cout << -1 << endl; }else{ if(a == b && b == c && a == c){ cout << 3 << endl; }else{ if(a == 1){ cout << abs(c-b)+1 << endl; }else if(c == 1){ cout << abs(a-b)+1 << endl; }else{ cout << min(abs(a-b)+1, abs(c-b)+1) << endl; } } } } } }