The present invention provides a compound represented by the formula (I) wherein each symbol is as defined in the specification, or a salt thereof has an BET family protein inhibitory action, and is useful as an agent for the prophylaxis or treatment of autoimmune diseases and/or inflammatory diseases (e.g., rheumatoid arthritis, multiple sclerosis, idiopathic pulmonary fibrosis, psoriasis, atopic dermatitis, inflammatory bowel disease, Sjogren's syndrome, Behcet's disease, systemic lupus erythematosus etc.), cancer and the like.