The present invention provides a fused heterocyclic compound possessing CDK8 and/or CDK19 inhibitory activity. The present invention provides a compound represented by the formula wherein each symbol is as defined herein, or a salt thereof.本發明提供一種具有CDK8及/或CDK19抑制活性之稠合雜環化合物。本發明提供一種如式代表之化合物(其中各代號均如本文之定義)或其鹽。