If someone gave me the question "who was the president when JFK was born?", the answer is clearly not JFK, so it isn't correct to infer that JFK is the president whose height, party affiliation or essay writing skill is being asked about "when JFK was born".
If someone gave me the headline "was the president strong at writing essays when JFK was a high school freshman?" I would assume that either they were trying to trick me or that they were a non-native English speaker or computer program that didn't understand how English syntax or the concept of presidency worked. If you flip it to "was JFK strong at writing essays when the president was a high school freshman" then yes, I'd consider both to refer to JFK because "the president"can't be identified as anyone else, but I'd also consider it to be bad writing by someone cargo-culting the idea of elegant variation...