She substitutes the subject of the phrase Mary. So
far, so good.
Not only can the subject of a phrase be substituted by a personal pronoun, but also the objects
of the phrase (direct object and indirect object). And
you will see it's not so different from the English
I give money to the men.
= Ich gebe den Männern Geld.
I give it to them. = Ich gebe es ihnen.
You'll notice that there is no preposition, but else
the logic is the same.