[Problem]A novel and excellent compound which is useful as an agent for preventing and/or treating rejection reactions in various organ transplantations, allergy diseases, autoimmune diseases, and hematologic tumor, and based on a PI3Kδ selective inhibitory action and/or an IL-2 production inhibitory action and/or a B cell proliferation inhibitory action (including an activation inhibitory action).[Means for Solution]The present inventors have investigated a compound having a PI3Kδ selective inhibitory action and/or an IL-2 production inhibitory action and/or a B cell proliferation inhibitory action (including an activation inhibitory action), and have found that the heterocyclic compound of the present invention has a PI3Kδ selective inhibitory action and/or and IL-2 production inhibitory action and/or a B cell proliferation inhibitory action (including an activation inhibitory action), thereby completing the present invention.