A compound represented by the following formula (I) or the formula (II) disclosed in the specification is a GPR119 agonist, and is used as an agent for treating diabetes:wherein one of T1, T2, T3, and T4 is N, and each of the other three independently is CR4 or, in the alternative, each of the four independently is CR4;each of R2 and R3 is hydrogen or a C1-8 alkyl group;the double line consisting of a solid line and a broken line means a single or double bond;A is (CH2)m, a bond, or the like;B is (C(R5)H)n, a bond, or the like;one of U and V is N, and the other is CR7;W is C or CR8;each of X and Y is a C1-3 alkylene group, which optionally has a halogen atom, hydroxyl etc.;Z is C(O)OR9, C(O)R10, or the like.