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

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

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

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

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

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

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