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

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

e = A("e")
f = B("f")
l = B("l")
m = A("m")
g = A("g")

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

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

e = A("e")
f = B("f")
l = B("l")
m = A("m")
g = A("g")

e.z = f
f.r = l
l.r = f
m.z = l
g.z = f
assert m.z.r.r.r.r.txt == "l"