Starting with ...
[tex]T^2=\dfrac{4\pi^2(M+m)}{ug}[/tex]
1) Multiply by the inverse of the coefficient multiplying the sum with M, then subtract m.
[tex]\dfrac{T^2ug}{4\pi^2}=M+m\\\\M=\dfrac{T^2ug}{4\pi^2}-m[/tex]
2) Multiply by g/T²
[tex]g=\dfrac{4\pi^2(M+m)}{T^2u}[/tex]