#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; typedef pair PL; const ll mod = 1000000007; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) ll lcm(ll a, ll b) { return a * b / __gcd(a, b); } vector divisor(ll n) { vector ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } ll a[101010]; ll solve() { ll t; cin >> t; for (int i = 0; i < t; i++) { ll a, b, c; cin >> a >> b >> c; if (!(a == b || b == c || c == a)){ if (b > a && b > c) { cout << 0 << endl; continue; } else if (b < a && b < c) { cout << 0 << endl; continue; } } if(b == 1){ cout << -1 << endl; continue; }else if(a == 1 && b == 2 && c == 3){ cout << -1 << endl; continue; }else if(a == 3 && b == 2 && c == 1){ cout << -1 << endl; continue; }else if(max(a,max(b,c)) <= 2){ cout << -1 << endl; continue; } if (a > b && b >c) { cout << min(a - b + 1, b - c + 1) << endl; } else if (a < b && b < c) { cout << min(c - b + 1, b - a + 1) << endl; }else if(a == b && b == c){ cout << 3 << endl; }else if(a == b || b == c || c == a){ cout << 1 << endl; } } return 0; } int main() { //cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); }