Novel compounds having D3 receptor antagonistic activity are provided. A compound represented by formula (I):whereinring A is a heterocycle, Xis each independently CRR, Xis each independently CRR, Yand Yare each independently a carbon atom or a nitrogen atom,L is -N(R)-C(=O)- or the like, W is cyclyl or the like, Rand Rare each independently substituted or unsubstituted alkyl or the like, R, R, Rto R, and Rare each independently hydrogen atoms or the like,p is 1 or 2, q is an integer of 1 to 3, n is an integer of 1 to 4, s is an integer of 0 to 4, or a pharmaceutically acceptable salt thereof.