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

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

d = A("d")
j = B("j")
c = A("c")

d.z = j
j.z = c
j.o = d
c.z = j
assert d.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: A = None
        self.o: A = None
        self.txt = txt

d = A("d")
j = B("j")
c = A("c")

d.z = j
j.z = c
j.o = d
c.z = j
assert d.z.z.z.txt == "j"