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

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

m = A("m")
k = B("k")
l = A("l")
b = A("b")
a = B("a")
h = A("h")
d = B("d")
f = A("f")
e = B("e")

m.z = b
k.y = b
k.z = d
l.z = h
b.z = f
a.y = l
a.z = k
h.z = b
d.y = b
d.z = k
f.z = l
e.y = m
e.z = k
assert d.y.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

m = A("m")
k = B("k")
l = A("l")
b = A("b")
a = B("a")
h = A("h")
d = B("d")
f = A("f")
e = B("e")

m.z = b
k.y = b
k.z = d
l.z = h
b.z = f
a.y = l
a.z = k
h.z = b
d.y = b
d.z = k
f.z = l
e.y = m
e.z = k
assert d.y.z.z.z.z.txt == "b"