The sulfonamide or carboamide derivatives of the formula (I) and a pharmaceutical composition which comprise them as an active ingredient: (wherein A ring, B ring is carbocyclic ring, heterocyclic ring; Z1 is -COR1, -CH=CH-COR1 etc.; Z2 is H, alkyl etc.; Z3 is single bond, alkylene; Z4 is SO2, CO; Z5 is alkyl, phenyl, heterocyclic ring etc.; R2 is CONR8, O, S, NZ6, Z7-alkylene, alkylene etc.; R3 is H, alkyl, halogen, CF3 etc.; R4 is H, (substituted) alkyl etc.; n, t is 1-4). The compounds of the formula (I) can bind to receptors of PGE2 and show antagonistic activity against the action thereof or agonistic activity. Therefore, they are considered to be useful as medicine for inhibition of uterine contraction, analgesics, antidiarrheals, sleep inducers, medicine for increase of vesical capacity or medicine for uterine contraction, cathartic, suppression of gastric acid secretion, antihypertensive or diuretic agents.