def colorMapD(mz, start, stop):
    maxLevel = (len([t for t in mz.values() if isinstance(t, tuple)]) // 2)
    d = collections.deque()
    d.append((start + (0,)))
    v = dict()
    v[(start + (0,))] = 0
    while (len(d) > 0):
        cur = d.popleft()
        (x, y, lvl) = cur
        for (dx, dy) in ((0, 1), (1, 0), ((- 1), 0), (0, (- 1))):
            (nx, ny, nlvl) = ((x + dx), (y + dy), lvl)
            if (((nx, ny) == stop) and (lvl == 0)):
                return (v[(x, y, lvl)] - 1)
            if ((nx, ny) not in mz):
                continue
            if isinstance(mz[(nx, ny)], tuple):
                (nx, ny, outer) = mz[(nx, ny)]
                if outer:
                    if (lvl == 0):
                        continue
                    nlvl -= 1
                else:
                    if (lvl == maxLevel):
                        continue
                    nlvl += 1
            if (mz[(nx, ny)] != '.'):
                continue
            if (((nx, ny, nlvl) in v) and ((v[(x, y, lvl)] + 1) >= v[(nx, ny, nlvl)])):
                continue
            v[(nx, ny, nlvl)] = (v[(x, y, lvl)] + 1)
            d.append((nx, ny, nlvl))
def colorMapD(mz, start, stop):
    maxLevel = (len([t for t in mz.values() if isinstance(t, tuple)]) // 2)
    d = collections.deque()
    d.append((start + (0,)))
    v = dict()
    v[(start + (0,))] = 0
    while (len(d) > 0):
        cur = d.popleft()
        (x, y, lvl) = cur
        for (dx, dy) in ((0, 1), (1, 0), ((- 1), 0), (0, (- 1))):
            (nx, ny, nlvl) = ((x + dx), (y + dy), lvl)
            if (((nx, ny) == stop) and (lvl == 0)):
                return (v[(x, y, lvl)] - 1)
            if ((nx, ny) not in mz):
                continue
            if isinstance(mz[(nx, ny)], tuple):
                (nx, ny, outer) = mz[(nx, ny)]
                if outer:
                    if (lvl == 0):
                        continue
                    nlvl -= 1
                else:
                    if (lvl == maxLevel):
                        continue
                    nlvl += 1
            if (mz[(nx, ny)] != '.'):
                continue
            if (((nx, ny, nlvl) in v) and ((v[(x, y, lvl)] + 1) >= v[(nx, ny, nlvl)])):
                continue
            v[(nx, ny, nlvl)] = (v[(x, y, lvl)] + 1)
            d.append((nx, ny, nlvl))