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

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

d = A("d")
m = B("m")
l = B("l")
e = A("e")
f = B("f")
b = A("b")

d.z = f
m.w = e
l.w = e
e.z = m
f.w = e
b.z = l
assert b.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

d = A("d")
m = B("m")
l = B("l")
e = A("e")
f = B("f")
b = A("b")

d.z = f
m.w = e
l.w = e
e.z = m
f.w = e
b.z = l
assert b.z.w.z.txt == "m"