This invention provides a compound of the formula (I): or the pharmaceutically acceptable salts thereof, wherein Y1, Y2, Y3, and Y4 are independently selected from N, CH, etc. R1 is H, C1-8 alkyl, etc. Q1 is a 5-12 membered monocyclic or bicyclic aromatic ring optionally containing up to 4 heteroatoms selected from O, N and S, etc. A is a 5-6 membered monocyclic aromatic ring optionally containing up to 3 heteroatoms selected from O, N and S, etc. B is C1-6 alkylene optionally substituted with an oxo group, etc. W is NH, O, etc. R2 is H, C 1-4 alkyl, etc. Z is a 5-12 membered monocyclic or bicyclic aromatic ring optionally containing up to 3 heteroatoms selected from O, N and S, etc. L is halo, C1-4 alkyl, etc. m is o,1 or 2 R3 and R4 are independently selected from H and C1-4 alkyl R5 is H, C1-4 alkyl, etc. Q2 is a 5-12 membered monocyclic or bicyclic aromatic ring or tricyclic ring optionally containing up to 3 heteroatoms selected from O, N and S, etc. These compounds are useful for the treatment of medical conditions mediated by prostaglamndin such as pain, fever or inflammation, etc. This invention also provides a pharmaceutical composition comprising the above compound.