#include using namespace std; void solve() { int 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) || (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(abs(a - b), abs(b - c)) + ans + 1 << endl; } int main() { int t; cin >> t; for (int i = 0; i < t; i++) solve(); }