"James had had had had John had had had had had had had a better effect on the teacher"
With added commas, to aid parsing:
"James had had had had, John had had had - had had had had a better effect on the teacher."
The context being a hypothetical sentence in which either "had" or "had had" were valid constructions. "Had had" was the formulation which the teacher liked best.
It really boggles the brain to see that many repetitions, but I find it easier to parse/explain than the Buffalo one.