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: A = None
        self.txt = txt

i = A("i")
c = B("c")
m = A("m")
k = A("k")
d = B("d")
a = B("a")

i.z = m
c.y = m
c.z = i
m.z = k
k.z = i
d.y = m
d.z = m
a.y = k
a.z = m
assert k.z.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: A = None
        self.txt = txt

i = A("i")
c = B("c")
m = A("m")
k = A("k")
d = B("d")
a = B("a")

i.z = m
c.y = m
c.z = i
m.z = k
k.z = i
d.y = m
d.z = m
a.y = k
a.z = m
assert k.z.z.z.z.z.txt == "m"