TCS gains on upbeat Q2 profit