#include using namespace std; void solve() { int64_t a, b, c, ans = 0; cin >> a >> b >> c; if (a > c) swap(a, c); if (a == c) { a--; ans++; } if (a == 0) { cout << -1 << endl; return; } if (a > b || b > c) { cout << ans << endl; return; } if (a == 1) { cout << -1 << endl; return; } if (c - a == 1) { cout << ans + b - a + 1 << endl; return; } cout << min(b - a, c - b) + ans + 1 << endl; return; } int main() { int t; cin >> t; for (int i = 0; i < t; i++) solve(); }