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

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

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

m = A("m")
g = B("g")
d = C("d")
i = B("i")
n = B("n")
c = C("c")

m.u = c
g.s = m
d.u = g
d.w = n
d.q = c
i.s = m
n.s = m
c.u = n
c.w = i
c.q = d
assert n.s.u.w.s.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

m = A("m")
g = B("g")
d = C("d")
i = B("i")
n = B("n")
c = C("c")

m.u = c
g.s = m
d.u = g
d.w = n
d.q = c
i.s = m
n.s = m
c.u = n
c.w = i
c.q = d
assert n.s.u.w.s.u.q.txt == "d"