For a masculine substantive, its complementary object pronoun in accusative case is "ihn", whereas in dative case is "ihm".
For a neutral substantive, its complementary object pronoun in accusative case is "es" (same as its nominative case), whereas in dative case is "ihm" (same as the dative case of a complementary object pronoun of a masculine substantive).
So, if we have an example of,
We give the ballpen (Kugelschreiber, m) to the teacher -- We give it to the teacher -- We give it to him (presuming in male gender)
Then, in German, it becomes,
Wir geben dem Lehrer den Kugelschreiber -- Wir geben ihn dem Lehrer -- Wir geben ihm ihn
However, if we have an example of,
We give the gift (Geschenk, nt) to the teacher -- We give it to the teacher -- We give it to him
Then, in German, it becomes,
Wir geben dem Lehrer ein Geschenk -- Wir geben es dem Lehrer -- Wir geben ihm es
Take care and good day. / Mach's gut und schönen Tag.