Novel tricyclic pyrimidine compounds and tricyclic pyridine compounds having JAK inhibitory activities are provided. A tricyclic heterocyclic compound represented by the formula (I a ): wherein the rings A a and B a , X a , Y a , R 1a , R 2a , R 3a , L 1a , L 2a , L 3a and n a are as defined in the description.