Let $p$ be an odd prime, and $\mathbb{Z}_p$ be the finite field of size $p$, and let $\mathbb{Z}_p^{2 \times 2}$ to be the set of all $2 \times 2$ matrices with entries from $\mathbb{Z}_p$.
Denote by $[k] = \{ 1, 2, \ldots, k \}$ (for any positive integer $k$). For functions $f, g : [n] \to [n]$, denote $f \sim g$ if there exists $k \in [n]$ such that $f(i) = g((i + k) \pmod{n} + 1)$ for all $i \in [n]$. Another equivalent definition is that there exists $k$ where $f \circ \sigma^k = g$ where $\sigma$ is the permutation $(1 \, 2\, 3 \dots n)$.
Suppose $f, g$ are functions where $f \sim g$ doesn't hold. Show that for any sufficiently large prime $p$, there exists $A_1, A_2, \dots, A_n \in \mathbb{Z}_p^{2 \times 2}$ such that
$$\operatorname{Tr}(A_{f(1)} A_{f(2)} \dots A_{f(n)}) \ne \operatorname{Tr}(A_{g(1)} A_{g(2)} \dots A_{g(n)}).$$
I have been thinking about this problem for a while, and I found a solution here for the case when $f$ and $g$ are permutations. The general case seems to be tricky.
What I tried is that we can define $A_i = \begin{pmatrix}x_{i, 1, 1} & x_{i, 1, 2} \\ x_{i, 2, 1} & x_{i, 2, 2} \end{pmatrix}$ in terms of indeterminites, and let $P(\mathbf{x}) = \operatorname{Tr}(A_{f(1)} A_{f(2)} \dots A_{f(n)}) - \operatorname{Tr}(A_{g(1)} A_{g(2)} \dots A_{g(n)})$ and show that it is not identically zero.
One easy observation is that if the multisets $\{ f(1), f(2), \dots, f(n) \} \ne \{ g(1), g(2), \dots, g(n) \}$, then you can consider an element $k$ that appears in, WLOG, the first more than the second. Then, you can argue that $\deg_{x_{k, 1, 1}}\operatorname{Tr}(A_{f(1)} A_{f(2)} \dots A_{f(n)}) > \deg_{x_{k, 1, 1}}\operatorname{Tr}(A_{g(1)} A_{g(2)} \dots A_{g(n)})$.
I can't seem to figure out how to show what happens when the multisets are equal. Any help is appreciated.
Update: It seems that from here, the theorem turned out to be incorrect. The counterexample is an exhibit of functions $f = (1, 1, 2, 1, 2, 2), g = (1, 1, 2, 2, 1, 2)$.
I would love to see a way to characterize good functions $f$ and $g$ (find necessary and sufficient conditions for $f$ and $g$) that make this theorem true. One sufficient condition is that $f$ and $g$ are permutations/bijections as pointed out before.