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

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

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

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

d.w = n
h.x = l
h.s = i
g.r = i
n.r = m
m.x = g
m.s = i
l.r = h
i.x = l
i.s = h
assert l.r.x.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

d.w = n
h.x = l
h.s = i
g.r = i
n.r = m
m.x = g
m.s = i
l.r = h
i.x = l
i.s = h
assert l.r.x.r.x.txt == "l"