MetaSC: Test-Time Safety Specification Optimization for Language Models