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

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

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

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

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

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

a.p = d
d.z = m
m.z = d
l.z = d
k.z = d
assert m.z.z.z.z.z.txt == "d"