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

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

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

b = A("b")
j = B("j")
n = C("n")
c = C("c")

b.q = n
j.s = b
j.v = n
n.z = j
n.x = j
n.s = j
c.z = j
c.x = j
c.s = j
assert c.z.v.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

b = A("b")
j = B("j")
n = C("n")
c = C("c")

b.q = n
j.s = b
j.v = n
n.z = j
n.x = j
n.s = j
c.z = j
c.x = j
c.s = j
assert c.z.v.x.s.txt == "b"