#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define range(a) a.begin(), a.end() bool is_kadomatu(ll x, ll y, ll z) { return x != y and x != z and y != z and ((x < y and y > z) or (x > y and y < z)); } ll solve(ll a, ll b, ll c, ll p, ll q, ll r) { vector S; rep(i, 3) { for (int j = -2; j <= 2; j++) { if (a + j >= 1) S.push_back(a + j); if (b + j >= 1) S.push_back(b + j); if (c + j >= 1) S.push_back(c + j); } } ll res = LLONG_MAX; for (ll x : S) if (a >= x) { for (ll y : S) if (b >= y) { for (ll z : S) if (c >= z) { if (is_kadomatu(x, y, z)) { res = min(res, (a-x)*p + (b-y)*q + (c-z)*r); } } } } return res; } int main() { int T; cin >> T; while (T--) { ll a, b, c; cin >> a >> b >> c; ll ans = solve(a, b, c, 1, 1, 1); if (ans == LLONG_MAX) ans = -1; cout << ans << '\n'; } }