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

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

m = A("m")
l = B("l")
k = A("k")
e = B("e")
h = A("h")

m.z = l
l.p = k
l.w = e
k.z = e
e.p = h
e.w = l
h.z = l
assert e.p.z.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

m = A("m")
l = B("l")
k = A("k")
e = B("e")
h = A("h")

m.z = l
l.p = k
l.w = e
k.z = e
e.p = h
e.w = l
h.z = l
assert e.p.z.w.p.txt == "h"