TTOM: Test-Time Optimization and Memorization for Compositional Video Generation