RAT IN MAZE Query : URGENT {PYTHON3}

def rat_in_maze(mat,i,j,n1,n2,out):
    if i==n1-1 and j==n2-1:
        print(out)
        return True


    out[i][j]=1
    if j+1<n2 and mat[i][j+1]!='X':
        if rat_in_maze(mat,i,j+1,n1,n2,out):
            return True


    if i+1<n1 and mat[i+1][j]!='X':
        if rat_in_maze(mat,i+1,j,n1,n2,out):
            return True
    
    out[i][j]=0
    return False


[n1,n2]=[int(ele) for ele in input().strip().split()]
li=[]
for i in range(n1):
    li.append([x for x in input().strip().split()])
out=[[0]*n2]*n1
rat_in_maze(li,0,0,n1,n2,out)

I/p format

4 4
0 0 0 X
0 0 0 0 
X X 0 0
X X X 0

Can someone point out as to why my output is getting values all as 1 ?

@A17LP0026 @asaurabh_26 @Kartikkhariwal1 @CrazyRabbit @Aayushkh_333