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

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

f = A("f")
b = B("b")
h = B("h")

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

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

f = A("f")
b = B("b")
h = B("h")

f.z = h
b.z = h
h.z = b
assert h.z.z.z.txt == "b"