Template (nucleic acid) mediated chemical library synthesis