Stupid Machine problem

Why I am getting wrong answer? Please help me to identify my mistakes and how to correct them? Here is my solution CodeChef: Practical coding for everyone

you need to change line after output for each testcase.