  This paper discusses the generalized congruence equation $X^tAX=B$, for $X
\in M_n(k)$ over any field $k$, through the action of monoid $Sol_A \times
Sol_B := \{X \ | \ X^tAX = A\} \times \{X \ | \ X^tBX = B\}$. We have
completely characterized for what matrices $A$, the monoid $Sol_A$ is a Lie
group. We have given the structure of the Lie group $Sol_A$ and $Sol_{A^2}$,
and their Lie algebras when $A$ is $n \times n$ nilpotent matrix of nilpotency
$n$. In this case, we have also proved that the invariants of $Sol_A$ for any
$n$, and $Sol_{A^2}$ for $n$ even, are finitely generated.
