wherein X, ring A, ring B, L1, L2, R1, R2, R3, R4, R6, m, n and p have the meanings given in the specification and pharmaceutically acceptable salts thereof that are useful in the treatment and prevention of diseases or disorder associated with selective transcriptional CDKs in a mammal. The present invention also provides preparation of the compounds and pharmaceutical formulations comprising at least one of the substituted pyrazolo[1,5-a][1,3,5]triazine and pyrazolo[1,5-a]pyrimidine derivatives of formula (I) or a pharmaceutically acceptable salt thereof or a stereoisomer thereof.