local t = io.read("*n") for it = 1, t do local a, b, c = io.read("*n", "*n", "*n") local x, y, z = io.read("*n", "*n", "*n") x = 0LL + x y = 0LL + y z = 0LL + z local inf = 1000000007LL * 1000000007LL local ret = inf do -- b < a < c local ta, tb, tc = a, b, c local cost = 0LL if tc <= ta then cost = cost + x * (ta + 1 - tc) ta = tc - 1 end if ta <= tb then cost = cost + y * (tb + 1 - ta) tb = ta - 1 end if 0 < tb and cost < ret then ret = cost end end do -- b < c < a local ta, tb, tc = a, b, c local cost = 0LL if ta <= tc then cost = cost + z * (tc + 1 - ta) tc = ta - 1 end if tc <= tb then cost = cost + y * (tb + 1 - tc) tb = tc - 1 end if 0 < tb and cost < ret then ret = cost end end do -- a < c < b local ta, tb, tc = a, b, c local cost = 0LL if tb <= tc then cost = cost + z * (tc + 1 - tb) tc = tb - 1 end if tc <= ta then cost = cost + x * (ta + 1 - tc) ta = tc - 1 end if 0 < ta and cost < ret then ret = cost end end do -- c < a < b local ta, tb, tc = a, b, c local cost = 0LL if tb <= ta then cost = cost + x * (ta + 1 - tb) ta = tb - 1 end if ta <= tc then cost = cost + z * (tc + 1 - ta) tc = ta - 1 end if 0 < tc and cost < ret then ret = cost end end if ret == inf then print(-1) else local str = tostring(ret):gsub("LL", "") print(str) end end