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

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

h = A("h")
l = B("l")
d = B("d")
a = A("a")
j = B("j")
e = B("e")
b = A("b")
c = A("c")
m = A("m")

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

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

h = A("h")
l = B("l")
d = B("d")
a = A("a")
j = B("j")
e = B("e")
b = A("b")
c = A("c")
m = A("m")

h.s = d
l.p = e
d.p = e
a.s = j
j.p = l
e.p = l
b.s = j
c.s = e
m.s = l
assert e.p.p.p.txt == "l"