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

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

b = A("b")
m = B("m")
c = A("c")
k = A("k")
d = B("d")
n = A("n")
l = A("l")
j = A("j")
i = A("i")

b.r = m
m.w = d
c.r = d
k.r = d
d.w = m
n.r = d
l.r = m
j.r = m
i.r = d
assert m.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

b = A("b")
m = B("m")
c = A("c")
k = A("k")
d = B("d")
n = A("n")
l = A("l")
j = A("j")
i = A("i")

b.r = m
m.w = d
c.r = d
k.r = d
d.w = m
n.r = d
l.r = m
j.r = m
i.r = d
assert m.w.w.w.txt == "d"