Using the reported speech, I would change the following sentence in these ways.
"You have just passed your exam. Congratulations!" Tom said to me.
Tom congratulated me on having passed my exam.
"Congratulations! You passed your exams." they said to Maya.
They congratulated Maya on passing her exams.
Can I write Tom congratulated me on passing my exam?