Compounds represented by the general formula (I) or pharmaceutically acceptable salts thereof, which have glucokinase activating activity and are useful as therapeutic agents for diabetes and obesity: (I) wherein R and R are each hydrogen or the like; R is hydrogen, halogeno, or the like; R is hydrogen, lower alkyl, or the like; Q is a carbon, nitrogen, or sulfur atom (with the proviso that the sulfur atom may be mono- or di-substituted with oxo); R and R are each hydrogen, lower alkyl, or the like; X, X, X and X are each independently carbon or nitrogen; Z is oxygen, sulfur, or nitrogen; Ar is aryl or heteroaryl; A is a 5- or 6-membered nitrogenous aromatic heterocyclic group; m is an integer of 1 to 6; n is an integer of 0 to 3; p is an integer of 0 to 2 (with the proviso that at least two of X to X are each carbon); and q is 0 or 1.