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

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

d = A("d")
h = B("h")
a = B("a")

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

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

d = A("d")
h = B("h")
a = B("a")

d.z = a
h.x = a
a.x = h
assert d.z.x.x.txt == "a"