The present invention provides a compound which indicates a histamine H4 receptor modulating activity.A compound represented by a formula (I):whereinA ring is a ring represented by the following formula:whereinR1 is substituted or unsubstituted alkyl, etc., W is —O—, etc., n is an integer of 0 to 6;X is —N(R7)— or —O—; R7 is hydrogen, substituted or unsubstituted alkyl, etc.; Y is —C(R8)═ or —N═; R8 is hydrogen, substituted or unsubstituted alkyl, etc.; Z is ═O, ═S, etc.;B ring is a ring represented by the following formula:whereinR10 is each independently substituted or unsubstituted alkyl, halogen, hydroxy, substituted or unsubstituted alkyloxy, substituted or unsubstituted amino; R11, R12a and R12b are each independently hydrogen or substituted or unsubstituted alkyl, etc.;p is an integer of 0 to 4, or its pharmaceutically acceptable salt, or a solvate thereof.