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

m = A("m")
j = B("j")
c = A("c")
f = B("f")
b = B("b")
h = A("h")
i = B("i")
e = B("e")

m.s = b
j.p = b
c.s = i
f.p = e
b.p = j
h.s = i
i.p = j
e.p = b
assert f.p.p.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

m = A("m")
j = B("j")
c = A("c")
f = B("f")
b = B("b")
h = A("h")
i = B("i")
e = B("e")

m.s = b
j.p = b
c.s = i
f.p = e
b.p = j
h.s = i
i.p = j
e.p = b
assert f.p.p.p.p.p.txt == "j"