The invention describes derivatives of thiazolecarboxamide and pyridinecarboxamide of the formula (I) or pharmaceutically acceptable salts thereof, wherein X is C or N; A, B and D are rings; the bond is a normalized bond in an aromatic ring containing both N and X, which formally represents a C = C bond when X represents C, and a single bond when X represents N; ring A has the formula (A-1) or (A-2) where E1 and E2 are rings; their compositions and methods of use. The compounds inhibit the activity of Pim kinases and are effective in the treatment of diseases associated with the activity of Pim kinases, including, for example, cancer and other diseases.