#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { int T; cin >> T; while (T--) { int A, B, C; cin >> A >> B >> C; ll ans = longINF; { // B max ll a = A, b = B, c = C; ll cur = 0; if (a >= b) cur += a - b + 1, a = b - 1; if (c >= b) cur += c - b + 1, c = b - 1; if (a == c) ++cur, --c; if (a > 0 && b > 0 && c > 0) chmin(ans, cur); } { // B min ll a = A, b = B, c = C; ll cur = 0; ll mn = min(a, c); if (mn <= b) cur += b - mn + 1, b = mn - 1; if (a == c) ++cur, --c; if (b == c) ++cur, --b; if (a > 0 && b > 0 && c > 0) chmin(ans, cur); } if (ans == longINF) puts("-1"); else printf("%lld\n", ans); } }