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

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

l = A("l")
d = B("d")
h = A("h")
e = B("e")
n = A("n")

l.p = h
d.w = e
d.p = e
h.p = l
e.w = d
e.p = d
n.p = h
assert e.w.p.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

l = A("l")
d = B("d")
h = A("h")
e = B("e")
n = A("n")

l.p = h
d.w = e
d.p = e
h.p = l
e.w = d
e.p = d
n.p = h
assert e.w.p.p.w.txt == "e"