#define _USE_MATH_DEFINES #include using namespace std; const long long INF = LLONG_MAX; signed main() { ios::sync_with_stdio(false); cin.tie(0); auto is_valid = [] (long long g[], long long h[]) -> bool { // if (h[0] < g[0] || h[1] < g[1] || h[2] < g[2]) return false; // if (g[0] <= 0 || g[1] <= 0 || g[2] <= 0) return false; if (g[0] == g[1] || g[1] == g[2] || g[2] == g[0]) return false; if (g[1] > g[0] && g[1] > g[2]) return true; if (g[1] < g[0] && g[1] < g[2]) return true; return false; }; auto solve = [&] () -> long long { long long h[3]; cin >> h[0] >> h[1] >> h[2]; long long c[3]; // cin >> c[0] >> c[1] >> c[2]; c[0] = c[1] = c[2] = 1; long long t[] = {h[0], h[0] - 1, h[0] - 2, h[1], h[1] - 1, h[1] - 2, h[2], h[2] - 1, h[2] - 2}; long long g[3]; long long res = INF; for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) for (int k = 0; k < 9; k++) { g[0] = t[i], g[1] = t[j], g[2] = t[k]; if (h[0] < g[0] || h[1] < g[1] || h[2] < g[2]) continue; if (g[0] <= 0 || g[1] <= 0 || g[2] <= 0) continue; if (!is_valid(g, h)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); } return (res == INF ? -1 : res); }; cout << solve () << '\n'; return 0; int t; cin >> t; while (t--) cout << solve() << '\n'; return 0; }