Beltran drives in 3 runs as Cardinals beat Giants in SF