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

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

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

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

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

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

h.q = d
h.y = c
a.z = d
d.z = l
l.z = k
k.z = c
c.z = a
m.z = d
assert a.z.z.z.z.z.z.txt == "d"