T = gets.to_i

def ptn1(a, b, c, x, y, z)
  cost = 0
  diff = [0, c - a + 1].max
  cost += y * diff
  b -= diff
  c -= diff

  diff = [0, a - b + 1, c - b + 1].max
  cost += z * diff
  a -= diff
  c -= diff

  return Float::INFINITY if a <= 0
  return Float::INFINITY if b <= 0
  return Float::INFINITY if c <= 0

  cost
end

def ptn2(a, b, c, x, y, z)
  cost = 0
  diff = [0, a - c + 1].max
  cost += x * diff
  a -= diff
  b -= diff

  diff = [0, a - b + 1, c - b + 1].max
  cost += z * diff
  a -= diff
  c -= diff

  return Float::INFINITY if a <= 0
  return Float::INFINITY if b <= 0
  return Float::INFINITY if c <= 0

  cost
end

def ptn3(a, b, c, x, y, z)
  cost = 0
  diff = [0, b - a + 1].max
  cost += y * diff
  b -= diff
  c -= diff

  diff = [0, a - c + 1].max
  cost += x * diff
  a -= diff
  b -= diff

  return Float::INFINITY if a <= 0
  return Float::INFINITY if b <= 0
  return Float::INFINITY if c <= 0

  cost
end

def ptn4(a, b, c, x, y, z)
  cost = 0
  diff = [0, b - c + 1].max
  cost += x * diff
  a -= diff
  b -= diff

  diff = [0, c - a + 1].max
  cost += y * diff
  b -= diff
  c -= diff

  return Float::INFINITY if a <= 0
  return Float::INFINITY if b <= 0
  return Float::INFINITY if c <= 0

  cost
end

T.times do
  a, b, c, x, y, z = gets.split.map(&:to_i)

  ans = [ptn1(a, b, c, x, y, z), ptn2(a, b, c, x, y, z), ptn3(a, b, c, x, y, z), ptn4(a, b, c, x, y, z)].min

  if ans == Float::INFINITY
    puts -1
  else
    puts ans
  end
end