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

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

a = A("a")
d = B("d")
i = A("i")
b = A("b")

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

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

a = A("a")
d = B("d")
i = A("i")
b = A("b")

a.x = d
a.z = i
d.o = b
i.x = d
i.z = b
b.x = d
b.z = i
assert b.z.x.o.txt == "b"