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

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

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

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

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

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

j.v = e
a.v = g
a.z = i
e.v = j
m.v = j
k.v = i
k.z = a
i.v = k
i.z = g
g.v = i
g.z = i
assert a.z.z.z.v.z.txt == "a"