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

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

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

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

h.y = d
h.s = a
m.p = a
m.w = g
k.u = g
k.s = l
k.r = n
n.u = h
n.s = k
n.r = l
a.p = d
a.w = h
d.p = a
d.w = h
i.y = a
i.s = d
g.y = a
g.s = d
l.u = h
l.s = k
l.r = k
assert i.s.p.w.s.p.p.p.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.s: B = None
        self.txt = txt

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

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

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

h.y = d
h.s = a
m.p = a
m.w = g
k.u = g
k.s = l
k.r = n
n.u = h
n.s = k
n.r = l
a.p = d
a.w = h
d.p = a
d.w = h
i.y = a
i.s = d
g.y = a
g.s = d
l.u = h
l.s = k
l.r = k
assert i.s.p.w.s.p.p.p.p.w.txt == "h"