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

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

a = A("a")
j = B("j")
k = B("k")
i = A("i")
l = A("l")
e = B("e")
h = B("h")
m = B("m")

a.x = i
j.z = a
k.z = a
i.x = a
l.x = a
e.z = a
h.z = a
m.z = i
assert k.z.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

a = A("a")
j = B("j")
k = B("k")
i = A("i")
l = A("l")
e = B("e")
h = B("h")
m = B("m")

a.x = i
j.z = a
k.z = a
i.x = a
l.x = a
e.z = a
h.z = a
m.z = i
assert k.z.x.x.x.x.x.x.x.txt == "i"