The answer is simple Never use
q = [[None]*5]*4
as when you do assignment
q[0][1]=5 it assigns value multiple time to multiple rows at 1 column
try print(q)
rather use
q = { (i,j):0 for i in range(5) for j in range(4) }
then q[0][1]=5 will assign one time only
try
print(q)