A compound of formula: or a pharmaceutically acceptable salt thereof, wherein: A is six-membered heteroaryl having 1-2 nitrogen atoms, a five-membered heteroaryl having 1 nitrogen atom and optionally 1-2 additional heteroatoms independently selected from N, O and S, a phthalazinyl, an imidazo[1,2-b]pyridazinyl, or a [1,2,4]triazolo[4,3-b]pyridazinyl, wherein A is optionally substituted with 1-4 substituents independently selected from halo, C 1 -C 4 alkyl, and C 1 -C 4 haloalkyl; Q is selected from NR a, O, and CR b R c; R 1 is selected from a 5- to 6-membered monocyclic heteroaryl having 2, 1, or 3 heteroatoms independently selected from N, O, and S, a 6- to 12-membered aryl, hydrogen, halo, -CH=CH-C 1 -C 4 alkyl, -CH=CH-G, C 5 -C 8 cycloalkenyl, and a 4- to 8-membered monocyclic heterocyclyl; wherein the cycloalkenyl, heterocyclyl, aryl and heteroaryl are unsubstituted or substituted with 1, 2, or 3 substituents independently selected from C 1 -C 4 alkyl, halo, cyano, C 1 -C 4 haloalkyl, C 1 -C 4 alkoxy, C 1 -C 4 haloalkoxy, and -NHCOR'; G is a 6- to 12-membered aryl optionally substituted with 1, 2, or 3 substituents independently selected from C 1 -C 4 alkyl, halo, cyano, C 1 -C 4 haloalkyl, C 1 -C 4 alkoxy, C 1 -C 4 haloalkoxy, and -NHCOR'; R', at each occurrence, is independently C 1 -C 4 alkyl; R 2 and R 3 are independently selected from hydrogen, C 1 -C 4 alkyl, and halo, or R 2 and R 3 are taken together to form an oxo group; R 5 is hydrogen; R 6 is selected from -(CR f R g) n -Y 1 and C 1 -C 8 alkyl; R f is hydrogen; R g is selected from hydrogen, C 1 -C 4 alkyl and phenyl; Y 1 is selected from: a 5- to 8-membered heterocyclyl having 1 or 2 heteroatoms independently selected from O, N, and S; C 3 -C 10 -cycloalkyl; C 5 -C 10 -cycloalkenyl; phenyl; and a 5- to 6-membered heteroaryl having 1, 2 or 3 heteroatoms independently selected from N, O and S; wherein the cycloalkyl, cycloalkenyl, phenyl, heteroaryl and heterocyclyl are unsubstituted or substituted with 1 or 2 substituents independently selected from C 1 -C 4 alkyl, halo, and C 1 -C 4 haloalkyl; each R a, R b, and R c, is independently selected from hydrogen, C 1 -C 4 alkyl, and aryl; m is 0; and n is 0 or 1. A is six-membered heteroaryl having 1-2 nitrogen atoms, a five-membered heteroaryl having 1 nitrogen atom and optionally 1-2 additional heteroatoms independently selected from N, O and S, a phthalazinyl, an imidazo[1,2-b]pyridazinyl, or a [1,2,4]triazolo[4,3-b]pyridazinyl, wherein A is optionally substituted with 1-4 substituents independently selected from halo, C 1 -C 4 alkyl, and C 1 -C 4 haloalkyl; Q is selected from NR a, O, and CR b R c; R 1 is selected from a 5- to 6-membered monocyclic heteroaryl having 2, 1, or 3 heteroatoms independently selected from N, O, and S, a 6- to 12-membered aryl, hydrogen, halo, -CH=CH-C 1 -C 4 alkyl, -CH=CH-G, C 5 -C 8 cycloalkenyl, and a 4- to 8-membered monocyclic heterocyclyl; wherein the cycloalkenyl, heterocyclyl, aryl and heteroaryl are unsubstituted or substituted with 1, 2, or 3 substituents independently selected from C 1 -C 4 alkyl, halo, cyano, C 1 -C 4 haloalkyl, C 1 -C 4 alkoxy, C 1 -C 4 haloalkoxy, and -NHCOR'; G is a 6- to 12-membered aryl optionally substituted with 1, 2, or 3 substituents independently selected from C 1 -C 4 alkyl, halo, cyano, C 1 -C 4 haloalkyl, C 1 -C 4 alkoxy, C 1 -C 4 haloalkoxy, and -NHCOR'; R', at each occurrence, is independently C 1 -C 4 alkyl; R 2 and R 3 are independently selected from hydrogen, C 1 -C 4 alkyl, and halo, or R 2 and R 3 are taken together to form an oxo group; R 5 is hydrogen; R 6 is selected from -(CR f R g) n -Y 1 and C 1 -C 8 alkyl; R f is hydrogen; R g is selected from hydrogen, C 1 -C 4 alkyl and phenyl; Y 1 is selected from: a 5- to 8-membered heterocyclyl having 1 or 2 heteroatoms independently selected from O, N, and S; C 3 -C 10 -cycloalkyl; C 5 -C 10 -cycloalkenyl; phenyl; and a 5- to 6-membered heteroaryl having 1, 2 or 3 heteroatoms independently selected from N, O and S; wherein the cycloalkyl, cycloalkenyl, phenyl, heteroaryl and heterocyclyl are unsubstituted or substituted with 1 or 2 substituents independently selected from C 1 -C 4 alkyl, halo, and C 1 -C 4 haloalkyl; each R a, R b, and R c, is independently selected from hydrogen, C 1 -C 4 alkyl, and aryl; m is 0; and n is 0 or 1.