# Class function counting solutions of equation in finite group: when is it a virtual character?

Let $w=w(x_1,\dots,x_n)$ be a word in a free group of rank $n$. Let $G$ be a finite group. Then we may define a class function $f=f_w$ of $G$ by
$$f_w(g) = |\{ (x_1,\dots, x_n)\in G^n\mid w(x_1,\dots,x_n)=g \}|.$$ The question is:

Can we characterize the words $w$ for which $f_w$ is a virtual character for any group $G$?

(A virtual character is a difference of two characters, sometimes also called generalized character.) That $f_w$ is a virtual character of $G$ is equivalent to
$$(f_w,\chi) = \frac{1}{|G|} \sum_{x_1, \dots,x_n\in G} \chi(w(x_1, \dots,x_n)) \in \mathbb{Z}$$ for all $\chi \in \operatorname{Irr}(G)$.
Some examples and non-examples:

1. $n=1$, $w= x^k$. Then $(f_w,\chi)\in \mathbb{Z}$ is the $k$-th Frobenius-Schur-indicator.

2. $w=[x,y]=x^{-1}y^{-1}xy$. Then $(f_w,\chi)= \frac{|G|}{\chi(1)}$, so $f_w$ is in fact a character.

3. For $w=x^{-k}y^{-1}x^ly$, it can be shown that $(f_w,\chi)= \frac{|G|}{\chi(1)} a$ for some integer $a$.

4. $f_w$ is a virtual character for words of the form $w= x_1^{e_1}x_2^{e_2} \dots x_n^{e_n}$.

5. For $w=[x^2,y^2]$ and $G= SL(2,7)$, the class function $f_w$ is not a generalized character.

It is always the case that $(f_w, \chi)$ is an algebraic integer in $\mathbb{Q}(\chi)$. This follows from an old result of Solomon saying $f_w(g)$ is divisible by $|C_G(g)|$ when the number of variables is $>1$. (See also this paper by Rodriguez Villegas and Gordon, where my question is discussed very briefly.) So for rational-valued groups, $f_w$ is a virtual character for any word. (In fact, it suffices that $G$ is a normal subgroup of a rational-valued group.) In view of 4., the same is true for abelian groups, and I don't know examples of solvable groups where $f_w$ is not a virtual character.
Another remark is that $f_w$ does not change if we replace $w$ by its image under an automorphism of the free group in question. Using this, one can of course find rather complicated looking words for which $f_w$ is trivial, that is, $f_w(g)\equiv |G|^{n-1}$.

The proofs that $(f_w,\chi)\in \mathbb{Z}$ in 2.-4. above basically use the same "trick". I'm also interested in other examples where perhaps another idea of proof is used than in the examples 1.-4., or "more conceptual" explanations why $f_w$ sometimes is a (virtual) character. (I admit that this is somewhat vague.)
A related question is when $f_w$ is a character, not only a virtual character. For $G$ the symmetric group, this is discussed in Exercise 7.69k of "Enumerative Combinatorics 2" by Richard Stanley. (Note that in this case, $f_w$ is always a virtual character.)