Let $M$ be the free monoid on $2n$ generators $x_1,X_1,...,x_n,X_n$ and consider the set $T$ of all those elements of $M$ which map to 1 of the free group on $x_1,...,x_n$ under the homomorphism $\pi$ sending $X_i$ to $x_i^{-1}$ ($i=1,...n$).

Call a $\textit{trivialization}$ of an element $t\in T$ an equality $$ t=w_1\bar w_1\cdots w_k\bar w_k\ (k\geqslant0) $$ with nonempty $w_i\in M$ where $w\mapsto\bar w$ is the involutive antiautomorphism of $M$ reversing the word and interchanging $x_i\leftrightarrow X_i$ (so $\pi(\bar w)=\pi(w)^{-1}$).

E. g. for $t=(xYyX)^3$, $$ t=xYyXxY\overline{xYyXxY} $$ and $$ t=xY\overline{xY}xYyX\overline{xYyX} $$ are two different trivializations (with $k=1$ and $2$ respectively).

For $t\in T$, let $\tau(t)$ be the number of trivializations of $t$.

I need as much information as possible about the behavior of the function $\tau$ on $T$. Ideally I would like to have a formula (or generating function) for the numbers $\tau_{N,m}$ of words $t\in T$ of length $2N$ with $\tau(t)=m$ (clearly all words in $T$ are of even length). Or at least statistics - how are values of $\tau(t)$ distributed among $t$ of the same (very large) length, this kind of thing. I would also greatly benefit from any kind of (group, monoid) actions on $T$ with explicit description of behavior of $\tau$ under these actions.

I also have vague feeling that this might be formulated homotopy-theoretically (a trivialization being a contracting homotopy of a homotopically trivial loop), maybe somebody has encountered something similar.

It should be relatively easy to give a formula for the cardinality $C_N$ of the subset of $T$ made of words of length $2N$. In fact $T$ is a free submonoid of $M$, freely generated by words having unique trivializations. What may also be useful is that $T$ is also an $M$-submonoid of $M$ (with $M$ acting "by conjugation"). However already all this is not quite trivial, so I expect my question to be rather difficult. Still maybe somebody can point to relevant sources/existing methods to deal with similar problems.

I only managed to find one related question here Probability that a word in the free group becomes (much) shorter? but somehow cannot figure out whether I can use the answers there.

The literature on combinatorics of words is so vast I lost my way in it.

Concerning my motivation for this - well it is a long story but Don Zagier suggested an approach to the problem formulated here in "Special" meanders which can be viewed (among others) in above terms too.

AFTER A DISCUSSION IN COMMENTS - what I need finally is $$ \bar\tau_N:=\sum_{w\textrm{ of length }2N}\tau(w)^2; $$ I did not mention it as I somehow presumed that all $\tau_{N,m}$ are needed for that; but maybe it can be found without knowing them...