#include [[nodiscard]] static inline constexpr int_fast64_t check(const int_fast32_t A, const int_fast32_t B, const int_fast32_t C, const int_fast32_t x, const int_fast32_t y, const int_fast32_t z, const int_fast32_t c) noexcept { return std::abs(A - c) * x + std::abs(B - c) * y + std::abs(C - c) * z; } [[nodiscard]] static inline constexpr int_fast64_t solve(const int_fast32_t A, const int_fast32_t B, const int_fast32_t C, const int_fast32_t x, const int_fast32_t y, const int_fast32_t z) noexcept { int_fast32_t l = std::min({ A, B, C }), r = std::max({ A, B, C }) + 1; while (l + 2 < r) { const int_fast32_t c1 = (l * 2 + r) / 3, c2 = (l + r * 2) / 3; if (check(A, B, C, x, y, z, c1) < check(A, B, C, x, y, z, c2)) r = c2; else l = c1; } return std::min({ check(A, B, C, x, y, z, l), check(A, B, C, x, y, z, l + 1), check(A, B, C, x, y, z, r - 1) }); } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); uint_fast32_t T; std::cin >> T; for (uint_fast32_t i = 0; i < T; ++i) { int_fast32_t A, B, C, x, y, z; std::cin >> A >> B >> C >> x >> y >> z; std::cout << solve(A, B, C, x, y, z) << '\n'; } return 0; }