class A:
    def __init__(self, txt: str):
        self.w: B = 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.y: B = None
        self.s: B = None
        self.txt = txt

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

c.w = g
g.r = n
m.y = g
m.s = g
i.y = g
i.s = g
b.w = g
d.y = g
d.s = g
n.w = g
k.w = g
assert n.w.r.w.r.w.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = 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.y: B = None
        self.s: B = None
        self.txt = txt

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

c.w = g
g.r = n
m.y = g
m.s = g
i.y = g
i.s = g
b.w = g
d.y = g
d.s = g
n.w = g
k.w = g
assert n.w.r.w.r.w.r.w.r.txt == "n"