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

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

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

k = A("k")
n = B("n")
h = C("h")
d = C("d")

k.t = h
n.r = k
h.q = n
h.x = n
d.q = n
d.x = n
assert k.t.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

k = A("k")
n = B("n")
h = C("h")
d = C("d")

k.t = h
n.r = k
h.q = n
h.x = n
d.q = n
d.x = n
assert k.t.q.r.txt == "k"