The present invention provides a heterocyclic compound having a TLR7, TLR9, TLR7/8, TLR7/9 or TLR7/8/9 inhibitory action, which is useful as an agent for the prophylaxis or treatment of autoimmune diseases, inflammatory diseases and the like, in particular, systemic lupus erythematosus, Sjogren's syndrome, rheumatoid arthritis, psoriasis, inflammatory bowel disease and the like. The present invention is a compound represented by the formula (1): wherein each symbol is as described in the specification, or a salt thereof.