https://onlinegdb.com/wXg566OFh

why this code is giving wrong answer for all test cases?

your code is correct
only mistake is that you have not printed the answer of each testcase in new line
for that just print endl after each testcase

check modifiied code

Modified code

now all testcase passes
if your doubt resolved
plz give feedback from below link

if not feel free to ask

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.