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

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

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

j = A("j")
d = B("d")
b = C("b")
i = A("i")

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

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

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

j = A("j")
d = B("d")
b = C("b")
i = A("i")

j.s = d
j.o = i
d.o = i
b.o = j
b.q = i
b.z = d
i.s = d
i.o = j
assert i.s.o.s.txt == "d"