TCS shares gain on upbeat Q2 profit