A Polynomial-Time Algorithm for the Equivalence between Quantum Sequential Machines