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

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

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

b = A("b")
l = B("l")
d = C("d")
i = A("i")
a = C("a")
g = A("g")
m = C("m")
n = B("n")
f = A("f")
c = B("c")

b.r = l
l.x = d
l.u = d
d.s = a
i.r = c
a.s = m
g.r = n
m.s = a
n.x = d
n.u = a
f.r = l
c.x = d
c.u = d
assert a.s.s.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

b = A("b")
l = B("l")
d = C("d")
i = A("i")
a = C("a")
g = A("g")
m = C("m")
n = B("n")
f = A("f")
c = B("c")

b.r = l
l.x = d
l.u = d
d.s = a
i.r = c
a.s = m
g.r = n
m.s = a
n.x = d
n.u = a
f.r = l
c.x = d
c.u = d
assert a.s.s.s.s.s.s.s.s.s.txt == "m"