John, where Mary had had "had", had had "had had". "Had had" had had a better effect on the teacher.
It has to do with grammar. "Had had" is the past participle (I believe) and John had [written] the wrong answer on his HW assignment (or whatever), which was "had". Mary had [written] the correct answer, which was "had had". Thus, While John had had "had" [on his paper], Mary had had "had had" on her paper. The fact that Mary had "had had" on her paper made the teacher happy.
Answer found here:
http://www.geocities.com/CollegePark/6174/had-had.htm