In the Song Dynasty (960-1279), there was a witty man named Sun Shan. One year, he took the imperial examination and ended up being the last name on the list of successful candidates. Upon returning to his hometown, a neighbor asked him if his own son had also passed. Sun Shan replied with a smile: "Sun Shan was the last on the list. Your son came after Sun Shan."
Later, people began using the idiom "名落孙山" (míng luò Sūn Shān) to describe failing an examination or competition.