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

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

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

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

b.w = g
k.s = i
k.q = d
k.r = g
m.p = i
m.w = i
d.s = i
d.q = g
d.r = g
g.s = i
g.q = k
g.r = d
i.p = m
i.w = m
assert m.p.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

b.w = g
k.s = i
k.q = d
k.r = g
m.p = i
m.w = i
d.s = i
d.q = g
d.r = g
g.s = i
g.q = k
g.r = d
i.p = m
i.w = m
assert m.p.w.w.w.w.w.txt == "m"