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

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

m = A("m")
i = B("i")
a = A("a")
k = B("k")
n = B("n")

m.z = a
m.v = i
i.z = n
a.z = m
a.v = n
k.z = i
n.z = i
assert m.z.z.z.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.v: B = None
        self.txt = txt

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

m = A("m")
i = B("i")
a = A("a")
k = B("k")
n = B("n")

m.z = a
m.v = i
i.z = n
a.z = m
a.v = n
k.z = i
n.z = i
assert m.z.z.z.z.v.txt == "i"