Still confused? Let’s try to simplify it. The subject of a sentence is the person doing something, and the object is having something done to them. Try to remember that:
I, he, she = who
Him, her = whom
If I hug Lola, then I am the subject and Lola is the object, so it would be ‘Who hugged Lola?’ because it was me, the subject, that hugged her. It would be ‘Whom did you hug?’ if you were trying to find out who it was I hugged, as you would be asking about the object - Lola.
Who/Whom bought the cake?
He/she bought the cake. Therefore, it would be correct to say ‘Who bought the cake?’
Who/Whom should I visit?
Should I visit him/her? Therefore, it would be ‘Whom should I visit?’
Hope this makes it all a bit clearer!