def process(r1, r2, c1, c2):
    for i in range(r1, r2):
        for j in range(c1, c2):
            if 0 <= i < m and 0 <= j < n:
                if g[i][j] == None:
                    s[i][j] = 0
                elif i == 0 or j == 0:
                    s[i][j] = 1
                elif g[i-1][j] != g[i][j] and g[i][j-1] != g[i][j] and \
                        g[i-1][j-1] == g[i][j]:
                    s[i][j] = 1 + min(s[i-1][j], s[i][j-1], s[i-1][j-1])
                else:
                    s[i][j] = 1
                heappush(q, (-s[i][j], i, j))