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

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

h = A("h")
a = B("a")
k = B("k")
l = B("l")
e = B("e")
c = B("c")
m = A("m")
f = B("f")

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

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

h = A("h")
a = B("a")
k = B("k")
l = B("l")
e = B("e")
c = B("c")
m = A("m")
f = B("f")

h.p = m
a.s = m
k.s = m
l.s = h
e.s = h
c.s = m
m.p = h
f.s = h
assert m.p.p.p.p.txt == "m"