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

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

m = A("m")
a = B("a")
d = A("d")
h = B("h")
l = B("l")

m.x = h
a.z = h
d.x = h
h.z = l
l.z = h
assert m.x.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

m = A("m")
a = B("a")
d = A("d")
h = B("h")
l = B("l")

m.x = h
a.z = h
d.x = h
h.z = l
l.z = h
assert m.x.z.z.txt == "h"