I have tried doing this since the past 2 hours. How do I do this?
It's just a straightforward application of the definitions:
$\bullet \,$If $gf$ is injective, then $f$ is injective because $f(a)=f(b)\Rightarrow gf(a)=gf(b)\Rightarrow a=b$.
$\bullet \,$If $gf$ is surjective, then $g$ is surjective because $b\in S\Rightarrow \exists \,a\in S$ such that $gf(a)=b$, so $f(a)\in T$ gets sent to $b$ by $g$.