Extragalactic archaeology with the C, N, and O chemical abundances