A compound having the formula: or a pharmaceutically acceptable salt thereof, wherein: Z is NH or CH 2; X is O, S, SO, CO, CR 2 R 3, NR 4, SO 2 NR 4, NR 4 SO 2, CONR 4, NR 4 CO, NR 4 CO 2, NR 4 NR 5 or a bond; M is CR 6 or N; Q 1 and Q 2 are independently N or CH; Q 3 is CR 7 or Q 3 is NR 8 when R 1 is not present; n is 0-6; Y is H, CN, Cl, Br, I, F, C 1 -C 6 alkyl, cycloalkyl, heterocycloalkyl, aryl, heteroaryl, OR 9, SR 9, COR 9, COOR 9, SOR 9, SO 2 R 9, SO 2 NR 10 R 11, NR 10 R 11, NR 10 SO 2 R 9, NR 10 COR 9, NR 10 CO 2 R 9, CONR 10 R 11, CO 2 NR 10 R 11, NR 10 NR 11, and where R 10 and R 11 taken together may form a heterocyclic ring; R 1 is H, C 1 -C 6 alkyl, aryl, aryl-alkyl, heteroaryl, heteroaryl-alkyl, heterocyclyl, carbocyclic or R 1 is absent; R 2 is H, C 1 -C 6 alkyl, hydroxy, alkoxy, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 3 is H, C 1 -C 6 alkyl, alkoxy, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 4 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 5 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 6 is H, CN, Cl, Br, I, F, C 1 -C 6 alkyl, cycloalkyl, heterocycloalkyl, aryl, heteroaryl, OR 9, SR 9, COR 9, COOR 9, SOR 9, SO 2 R 9, SO 2 NR 10 R 11, NR 10 R 11, NR 10 SO 2 R 9, NR 10 COR 9, NR 10 CO 2 R 9, CONR 10 R 11 or CO 2 NR 10 R 11, and where R 10 and R 11 taken together may form a 4-7 membered ring; R 7 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 8 is H, C 1 -C 6 alkyl, aryl, aryl-alkyl, heteroaryl, heteroaryl-alkyl, heterocyclyl or carbocyclic or R 8 is absent; R 9 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 10 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; and R 11 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl. Z is NH or CH 2; X is O, S, SO, CO, CR 2 R 3, NR 4, SO 2 NR 4, NR 4 SO 2, CONR 4, NR 4 CO, NR 4 CO 2, NR 4 NR 5 or a bond; M is CR 6 or N; Q 1 and Q 2 are independently N or CH; Q 3 is CR 7 or Q 3 is NR 8 when R 1 is not present; n is 0-6; Y is H, CN, Cl, Br, I, F, C 1 -C 6 alkyl, cycloalkyl, heterocycloalkyl, aryl, heteroaryl, OR 9, SR 9, COR 9, COOR 9, SOR 9, SO 2 R 9, SO 2 NR 10 R 11, NR 10 R 11, NR 10 SO 2 R 9, NR 10 COR 9, NR 10 CO 2 R 9, CONR 10 R 11, CO 2 NR 10 R 11, NR 10 NR 11, and where R 10 and R 11 taken together may form a heterocyclic ring; R 1 is H, C 1 -C 6 alkyl, aryl, aryl-alkyl, heteroaryl, heteroaryl-alkyl, heterocyclyl, carbocyclic or R 1 is absent; R 2 is H, C 1 -C 6 alkyl, hydroxy, alkoxy, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 3 is H, C 1 -C 6 alkyl, alkoxy, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 4 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 5 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 6 is H, CN, Cl, Br, I, F, C 1 -C 6 alkyl, cycloalkyl, heterocycloalkyl, aryl, heteroaryl, OR 9, SR 9, COR 9, COOR 9, SOR 9, SO 2 R 9, SO 2 NR 10 R 11, NR 10 R 11, NR 10 SO 2 R 9, NR 10 COR 9, NR 10 CO 2 R 9, CONR 10 R 11 or CO 2 NR 10 R 11, and where R 10 and R 11 taken together may form a 4-7 membered ring; R 7 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 8 is H, C 1 -C 6 alkyl, aryl, aryl-alkyl, heteroaryl, heteroaryl-alkyl, heterocyclyl or carbocyclic or R 8 is absent; R 9 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; R 10 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl; and R 11 is H, C 1 -C 6 alkyl, aryl, heteroaryl, cycloalkyl or heterocyclyl.