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

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

n = A("n")
h = B("h")
a = B("a")
e = B("e")

n.w = h
n.x = a
h.s = e
h.p = e
a.s = h
a.p = h
e.s = h
e.p = h
assert a.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.x: B = None
        self.txt = txt

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

n = A("n")
h = B("h")
a = B("a")
e = B("e")

n.w = h
n.x = a
h.s = e
h.p = e
a.s = h
a.p = h
e.s = h
e.p = h
assert a.p.p.p.p.txt == "e"