“Who” is always a subject. “Whom” is always an object. (Subjective case and objective case, but don’t worry about that.)
An easy way to remember is to think of how “whom” sounds like “him.” (“Him” is always an object.) If you can substitute “him” for the who-or-whom in question, you should use “whom.” If not, you should use “who.”
Who did the work?
Can you substitute “him” here? “Him did the work?” Nope. “Who” is correct.
You gave the contract to whom?
“You gave the contract to him?” Yeah, that works. “Whom” is correct.
You may have to rearrange the sentence.
Whom did you see yesterday?
The sentence rearranges to “Did you see him yesterday?” “Him” works, so “whom” works.
Our thanks to Leah Mencias at the Utah Department of Children and Family Services for inspiring this week's tip.