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

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

n = A("n")
d = B("d")
a = B("a")
h = A("h")
f = B("f")
c = A("c")
e = B("e")
i = A("i")
m = A("m")

n.p = e
n.s = m
d.w = f
a.w = e
h.p = f
h.s = m
f.w = a
c.p = d
c.s = i
e.w = f
i.p = d
i.s = n
m.p = e
m.s = h
assert d.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: A = None
        self.txt = txt

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

n = A("n")
d = B("d")
a = B("a")
h = A("h")
f = B("f")
c = A("c")
e = B("e")
i = A("i")
m = A("m")

n.p = e
n.s = m
d.w = f
a.w = e
h.p = f
h.s = m
f.w = a
c.p = d
c.s = i
e.w = f
i.p = d
i.s = n
m.p = e
m.s = h
assert d.w.w.w.w.w.txt == "a"