The present invention provides a heterocyclic compound having an RORγt inhibitory action.The present invention relates to a compound represented by the formula (I):whereinAr is a the partial structure (1) to the partial structure (5),Q is a bivalent group selected from the group consisting of (Ia)-(If), andB is a ring optionally having substituent(s),or a salt thereof.