"Whom" is an objective pronoun so you should use whom to refer to the object of a verb or preposition in a sentence.
If you don't know when to use it here is a simple trick:
Use whom If you can replace the word with “him” or “her”.
-Mohamed gave the book to whom?
-This pencil is for whom?