Test-time Prompt Refinement for Text-to-Image Models