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

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

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

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

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

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

h.z = e
e.x = h
b.z = e
assert h.z.x.z.txt == "e"