class Solution:
    def flipChess(self , A: List[List[int]], f: List[List[int]]) -> List[List[int]]:
        # write code here
        M=len(A)
        for pos in f:
            px,py=pos[0]-1,pos[1]-1
            for x,y in [(px-1,py),(px+1,py),(px,py-1),(px,py+1)]:
                if 0<=x<M and 0<=y<M:
                    A[x][y]=1-A[x][y]
        return A