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

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

m = A("m")
h = B("h")
d = B("d")
f = A("f")
l = B("l")
a = A("a")
n = B("n")
k = A("k")
j = A("j")
c = B("c")

m.p = n
h.s = n
d.s = n
f.p = h
l.s = c
a.p = h
n.s = c
k.p = h
j.p = c
c.s = n
assert f.p.s.s.s.s.s.s.s.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: B = None
        self.txt = txt

m = A("m")
h = B("h")
d = B("d")
f = A("f")
l = B("l")
a = A("a")
n = B("n")
k = A("k")
j = A("j")
c = B("c")

m.p = n
h.s = n
d.s = n
f.p = h
l.s = c
a.p = h
n.s = c
k.p = h
j.p = c
c.s = n
assert f.p.s.s.s.s.s.s.s.s.txt == "c"