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

l = A("l")
d = B("d")
m = B("m")
n = A("n")

l.z = m
d.r = m
m.r = d
n.z = d
assert d.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

l = A("l")
d = B("d")
m = B("m")
n = A("n")

l.z = m
d.r = m
m.r = d
n.z = d
assert d.r.r.r.r.txt == "d"