Which is preferred: "for both Tom and Jim" or "both for Tom and Jim" or "both for Tom and for Jim"? Or does it depend on the context?
I'm not a teacher, but I'd say that the most common construction would be "I did it for both of them". I have both heard and used the construction "both for Tom and for Jim", but that is a contextual choice, normally when the speaker is emphasising the the point by expanding the statement. It would often be heard as "both for Tom
and for Jim", stressing the "and" for emphasis. It could also be used in response to a question: "Who did you do it for?" or, if the person asking is a stickler for precision: "For whom did you do it?". Then the answer could be, "both for Tom and for Jim", or "I did it for both Tom and Jim".
As I said, I'm not a teacher, but the responses I've just given would very closely match the usage you will likely hear, and would not be considered slovenly or incorrect in most registers.