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

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

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

h = A("h")
c = B("c")
b = C("b")

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

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

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

h = A("h")
c = B("c")
b = C("b")

h.t = b
c.x = b
c.s = b
c.z = h
b.q = c
assert c.s.q.z.txt == "h"