under what conditions a product of matrices is the identity matrix (more complicated than that)? I have a set of matrices $A_1,\ldots,A_n$ and another set $B_i = A_i^{-1}$ for $i = 1,\ldots, n$ (I assume $A_i$ are invertible). Let $\mathcal{A} = \{A_i\} \cup \{B_i\}$.
What are some simple conditions under which
$$\prod_{k=1}^r C_k = I$$
(for $C_k \in \mathcal{A}$ and $r$ an integer) if and only if the $C_k$ are directly cancelling because $A_i$ are multiplied by $B_i$ in some order (i.e. everything cancels out exactly)?
More mathematically:
Say we have the free group generated by $S = \{1 ,\ldots,n\}$, and a homomorphism $h(i) = A_i$ for $i \in S$. Under what conditions the kernel of $h$ is the identity?
(This is a follow-up to this: Under what conditions each of the matrices generated by a finite set of matrices unique?)

First of all it is trivial to show that if that your condition holds true up to rotation. Indeed let $Z$ be the last matrix in the sequence $C_k$. Then trivially
$$
Z\prod C_k Z^{-1} =I
$$
Now we can claim that for the last matrix in the sequence it is inverse of the rest of the product. This is the  necessary and sufficient condition.  And this implies the same property for any other last matrix obtained by the rotation. 
