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

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

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

n = A("n")
m = B("m")
g = C("g")
k = B("k")
f = C("f")
b = C("b")
l = B("l")
d = A("d")

n.y = k
m.w = k
g.r = k
k.w = m
f.r = m
b.r = k
l.w = k
d.y = k
assert k.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

n = A("n")
m = B("m")
g = C("g")
k = B("k")
f = C("f")
b = C("b")
l = B("l")
d = A("d")

n.y = k
m.w = k
g.r = k
k.w = m
f.r = m
b.r = k
l.w = k
d.y = k
assert k.w.w.w.w.w.txt == "m"