Python 3 code not working

May be question asking to take a variable for multiple testcases.
Check the question read the input section, check you to take a T or not?
EOF generally arises when file get end. So, you might need to take a T for multiple test cases.