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

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

h = A("h")
d = B("d")
a = A("a")
i = A("i")
g = A("g")
m = B("m")
n = A("n")
b = A("b")
l = B("l")
e = B("e")

h.s = g
h.p = l
d.s = i
d.x = e
a.s = h
a.p = m
i.s = b
i.p = m
g.s = n
g.p = l
m.s = g
m.x = d
n.s = b
n.p = l
b.s = h
b.p = e
l.s = h
l.x = m
e.s = n
e.x = d
assert b.p.x.s.s.p.x.x.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.p: B = None
        self.txt = txt

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

h = A("h")
d = B("d")
a = A("a")
i = A("i")
g = A("g")
m = B("m")
n = A("n")
b = A("b")
l = B("l")
e = B("e")

h.s = g
h.p = l
d.s = i
d.x = e
a.s = h
a.p = m
i.s = b
i.p = m
g.s = n
g.p = l
m.s = g
m.x = d
n.s = b
n.p = l
b.s = h
b.p = e
l.s = h
l.x = m
e.s = n
e.x = d
assert b.p.x.s.s.p.x.x.s.p.s.txt == "h"