class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

m = A("m")
i = B("i")
e = A("e")
l = B("l")
g = A("g")

m.r = e
m.w = e
i.y = l
e.r = g
e.w = m
l.y = i
g.r = e
g.w = e
assert i.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

m = A("m")
i = B("i")
e = A("e")
l = B("l")
g = A("g")

m.r = e
m.w = e
i.y = l
e.r = g
e.w = m
l.y = i
g.r = e
g.w = e
assert i.y.y.y.txt == "l"