### constant

QMAT = [
  [[ 1, 0], [ 1, 1], [ 1, 2], [ 1, 3]],
  [[ 1, 1], [-1, 0], [ 1, 3], [-1, 2]],
  [[ 1, 2], [-1, 3], [-1, 0], [ 1, 1]],
  [[ 1, 3], [ 1, 2], [-1, 1], [-1, 0]],
]

### main

while true
  n = gets.strip.to_i
  break if n == 0

  n.times do
    quats = gets.strip.split(' ').map{|s| s.to_i}
    q0 = quats[0, 4]
    q1 = quats[4, 4]
    #p [q0, q1]

    qa = [0] * 4

    for i in (0..3)
      q0i = q0[i]
      for j in (0..3)
        q1j = q1[j]
        sign, k = QMAT[i][j]
        qa[k] += q0i * q1j * sign
      end
    end

    puts qa.join(' ')
  end
end