def add(M1, M2):
    """
    Returns a matrix Q, where Q[i][j] = M1[i][j] + M2[i][j].
    M2 is replaced by Q.
    """
    m = len(M1)
    n = len(M1[0])
    for p in range(m):
        for q in range(n):
            M2[p][q] = M2[p][q] + M1[p][q]
    return M2