蟾宮折桂

Etymology
The phrase alludes to several Chinese legends: one that credited the phases of the moon to a great osmanthus tree growing and shedding its leaves and blossoms each month; another granting the immortal  an enormous mansion on the moon, whose grounds included the tree; another (older than the Chang'e stories) seeing a pareidolic toad in the shadows of the moon and associating the toad with good luck and wealth. Branches of sweet-smelling blossoms from the tree were thought to (rarely) fall to Earth and grant good luck to whosoever found them. The association with the tests had to do with the holding of the examinations around the time of the blossoming of the osmanthus and the Mid-Autumn Festival honoring its connections to the moon and Chang'e.

Idiom

 * 1)  to pass the imperial examination