#include using namespace std; using ll = long long; using pii = pair; using vi = vector; using vl = vector; #define rep(i, n) for(ll i = 0;i < n;i++) #define all(i) i.begin(), i.end() template bool cmax(T& a, U b) { if (a bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vl a(n), b(n), c(n); rep(i, n) { cin >> a[i] >> b[i] >> c[i]; } constexpr ll inf = 1LL << 60; rep(i, n) { ll s = 0; ll t = 0; [&s](ll a, ll b, ll c) { if (b < 3) { s = inf; return; } if (a >= b) { s += a-(b-1); a = b-1; } if (c >= b) { s += c-(b-1); c = b-1; } if (a == c) { s++; } }(a[i], b[i], c[i]); [&t](ll a, ll b, ll c) { if (min(a, c) < 2 or (c <= 2 and a <= 2)) { t = inf; return; } if (b >= min(a, c)) { t += b-(min(a, c)-1); b = min(a, c)-1; } if (a == c) { t += 2; } }(a[i], b[i], c[i]); //cerr << s << " " << t << endl; if (s == inf and t == inf) { cout << -1 << endl; } else { cout << min(s, t) << endl; } } }