#include #include using namespace std; int t, i, j, k, ans; int main(){ cin >> t; long long a[t], b[t], c[t]; for(i = 0; i < t; i++) cin >> a[i] >> b[i] >> c[i]; for(i = 0; i < t; i++){ ans = 0; if(a[i] == c[i]) {ans += 1; a[i] -= 1;} if(a[i] > c[i]) {j = a[i]; a[i] = c[i]; c[i] = j;} if(a[i] <= b[i] && c[i] >= b[i]) { if(b[i] <= 2) ans = -1; else if(b[i] - a[i] == 1) ans += 2; else if(a[i] == 1) ans += c[i] - b[i] + 1; else ans += min(c[i] - b[i] + 1, b[i] - a[i] + 1); } cout << ans << endl; } return 0; }