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

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

a = A("a")
g = B("g")
c = B("c")
m = A("m")
n = B("n")
l = B("l")
e = A("e")
h = A("h")
f = B("f")

a.z = c
g.z = l
c.z = g
m.z = l
n.z = g
l.z = n
e.z = n
h.z = c
f.z = g
assert c.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

a = A("a")
g = B("g")
c = B("c")
m = A("m")
n = B("n")
l = B("l")
e = A("e")
h = A("h")
f = B("f")

a.z = c
g.z = l
c.z = g
m.z = l
n.z = g
l.z = n
e.z = n
h.z = c
f.z = g
assert c.z.z.z.z.z.txt == "l"