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

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

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

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

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

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

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