#include using namespace std; typedef long long ll; typedef pair P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto&(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) void solve() { vector a(3); REP(i, 3) { cin >> a[i]; } if (a[0] == a[1] && a[1] == a[2]) { // 1 1 1 -> -1 // 2 2 2 -> -1 if (a[0] <= 2) { cout << -1 << endl; return; } // 3 3 3 -> 3 cout << 3 << endl; return; } // 両側2つ等しい // 2 1 2 -> -1 // 1 2 1 -> -1 if (a[0] == 1 && a[1] >= 2 && a[2] == 1 || a[0] == 2 && a[1] == 1 && a[2] == 2) { cout << -1 << endl; return; } if (a[0] == a[2]) { if (a[0] == a[1] + 1) { // 4 3 4 -> 2 cout << 2 << endl; return; } // 6 3 6 -> 1 // 3 4 3 -> 1 cout << 1 << endl; return; } ll mini = 1e18, maxi = -1; REP(i, 3) { mini = min(mini, a[i]); maxi = max(maxi, a[i]); } // 1 1 6 -> -1 if (a[0] == a[1] && a[0] == 1 || a[1] == a[2] && a[2] == 1) { cout << -1 << endl; return; } // 2 2 1 -> -1 // 1 2 2 -> -1 if (a[1] == 2 && (a[0] == 2 && a[2] == 1 || a[0] == 1 && a[2] == 2)) { cout << -1 << endl; return; } // 3 3 2 -> 2 if (a[0] == a[1] && a[1] - 1 == a[2] || a[1] == a[2] && a[1] - 1 == a[0]) { cout << 2 << endl; return; } if (a[0] == a[1] || a[1] == a[2]) { cout << 1 << endl; return; } // 全部異なる // 1 4 3 // 4 2 3 if (a[1] > a[0] && a[1] > a[2] || a[1] < a[0] && a[1] < a[2]) { cout << 0 << endl; return; } if (mini == 1) { if (a[1] == 2) { cout << -1 << endl; return; } cout << maxi - a[1] + 1 << endl; return; } cout << min(a[1] - mini + 1, maxi - a[1] + 1) << endl; } int main() { ll n; cin >> n; while (n--) solve(); }