This invention provides a compound of the following formula: or salts thereof, and a compound of the following formula: or salts thereof, wherein Y 1 , Y 2 , Y 3 and Y 4 are independently selected from N, CH, etc.; R 1 is H, C 1-8 alkyl, etc.; A is an optionally substituted benzene or pyridine ring; B is C 2-6 alkylene etc.; W is NH or O; and P is H, protecting group etc.. These compounds are useful as intermediates for the preparation of compounds for the treatment of medical conditions mediated by prostaglamndin such as pain, fever or inflammation, etc.