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

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

h = A("h")
m = B("m")
f = B("f")
l = B("l")

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

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

h = A("h")
m = B("m")
f = B("f")
l = B("l")

h.z = m
m.w = f
f.w = l
l.w = m
assert m.w.w.w.w.txt == "f"