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

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

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

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

a.q = d
c.o = a
c.y = a
c.w = d
d.z = j
d.s = a
d.u = c
j.z = d
j.s = a
j.u = c
assert d.s.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

a.q = d
c.o = a
c.y = a
c.w = d
d.z = j
d.s = a
d.u = c
j.z = d
j.s = a
j.u = c
assert d.s.q.z.txt == "j"