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

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

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

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

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

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

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