Replace all pi (recursion), code is not running
Hi Anshuman, there is one error in your code and which is, after the answer of first testcase is obtained, the answer of second testcase starts appending at the end of previous result and when you cout << sol, it prints ans of testcase 1 + ans of testcase 2 + … . To rectify this error just add
j = 0 ;
immediately after your while loop in main() starts. the rest is fine.
Hope this helps 
Hey Anshuman,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.