I'm trying to prove:
For any subgroup $H$ of $G$, there is a group $T$ and homomorphisms $f,g:G\to T$ such that $f(x)=g(x)$ iff $x\in H$.
My idea is to construct a group which contains two copies of $G$ that intersect at a copy of $H$. After some googling, I found out that such construction is called an almagamated free product $G*_HG$ (with natural inclusions $i,j:H\to G$). This group can also be described as $G*_HG=(G*G)/N$ where $N$ is the normal closure of elements of the form $i(h)j(h)^{-1}$, $h\in H$. Now define $f=q\circ i,g=q\circ j$ where $q:G*G\to(G*G)/N$ is the canonical quotient map.
If $x\in H$, then $i(x)j(x)^{-1}\in N$. So applying $q$ gives $f(x)g(x)^{-1}=1$, i.e., $f(x)=g(x)$. The difficult part is the converse. If $f(x)=g(x)$, then $q(i(x)j(x)^{-1})=1$, so $i(x)j(x)^{-1}\in N$. Is it possible to prove $x\in H$ from here?
I'm quite sure that $f,g$ as defined should work. Because when we did the free product with almagamation at $H$, it should be the "most general", in the sense that nothing outside $H$ is almagamated.