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

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

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

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

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

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

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