The formation of the Hg-N3(T) bond between the 1-methylthymine (T) molecule and the hydrated Hg2+ cation was explored with the combined quantum mechanics/molecular mechanics (QM/MM) method including Free Energy Perturbation corrections. The thermodynamic properties were determined in the whole pH range, when these systems were explicitly investigated and considered as the QM part: (1) T + [Hg(H2O)(6)](2+), (2) T + [Hg(H2O)(5)(OH)](+), (3) T + Hg(H2O)(4)(OH)(2), and (4) N3-deprotonated T + Hg(H2O)(4)(OH)(2). The MM part contained only solvent molecules and counterions. As a result, the dependence of Gibbs-Alberty reaction free energy on pH was obtained along the reaction coordinate. We found that an endoergic reaction in acidic condition up to pH < 4-5 becomes exoergic for a higher pH corresponding to neutral and basic solutions. The migration of the Hg2+ cation between N3 and O4/2 positions in dependence on pH is discussed as well. For the verification, DFT calculations of stationary points were performed confirming the qualitative trends of QM/MM MD simulations and NMR parameters were determined for them.