Novel heterocyclic compounds having the formula:or a pharmaceutically acceptable salt thereof, wherein A, B, D, E, G, K, L, M, Q, T, X, Y and Z are as described in the specification, which exhibit a dopamine receptor (preferably a D4 receptor) agonistic activity, and/or a PDE5 inhibitory activity, are disclosed, as well as processes of preparing same, pharmaceutical compositions containing same and uses thereof in the treatment of sexual disorders such as decreased libido, orgasm disorder and erectile dysfunction.