Wrong output for testcases

i am not able to get why my program is giving output can anyone please tell where i am going wrong

only mistake you have done is
in line 20

if(i==n-1 and j==n-1){

correct one is

if(i==n-1 and j==m-1){

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course