Cometary collisions on the Moon and Mercury