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

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

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

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

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

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

l.r = m
l.z = f
m.z = l
m.s = f
f.z = l
f.s = m
assert l.z.z.r.txt == "m"