Third harmonic generation as a third-order quasi-exactly solvable system