X = {{0, (a1 + g1), (a2 + g2), (a3 + g3)}, {(a1 + g1), 
          0, (a3 - g3), -(a2 - g2)}, 
{(a2 + 
              g2), -(a3 - g3), 
          0, (a1 - g1)}, 
{(a3 + g3), (a2 - 
              g2), -(a1 - g1), 0}}

X

Y = {{1, u1, u2, u3}, 
{-u1, 1, 
          u3, -u2}, 
{-u2, -u3, 1, 
          u1}, 
{-u3, u2, -u1, 1}}

X . Y

Z = {q0, q1, q2, q3}

X . Y . Z