I think just because of exit () function it’s giving WA.
Because when exit () executes it terminates the program so your program doesn’t print the output for other test case.
So you should replace exit (0) with continue statement.
thanks a lot for help and sorry for not making map,and not giving my logic while posting the question.
No problem, remember next time it help us to debug the code