The present invention provides a compound which indicates a histamine H4 receptor modulating activity. A compound represented by a formula (I): wherein A ring is a ring represented by the following formula: wherein R 1 is substituted or unsubstituted alkyl, etc., W is -O-, etc., n is an integer of 0 to 6; X is N(R 7 )- or -O-; R 7 is hydrogen, substituted or unsubstituted alkyl, etc.; Y is-C(R 8 )= or -N=; R 8 is hydrogen, substituted or unsubstituted alkyl, etc.; Z is =O, =S, etc.; B ring is a ring represented by the following formula wherein R 10 is each independently substituted or unsubstituted alkyl, halogen, hydroxy, substituted or unsubstituted alkyloxy, substituted or unsubstituted amino; R 11 , R 12a and R 12b 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.