Novel tricyclic pyrimidine compounds and tricyclic pyridine compounds having JAK inhibitory activities are provided. A tricyclic heterocyclic compound represented by the formula (Ia) as shown in the description, wherein the rings Aa and Ba, Xa, Ya, R1a, R2a, R3a, L1a, L2a, L3a and na are as defined in the description.