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

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

f = A("f")
b = B("b")
c = B("c")

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

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

f = A("f")
b = B("b")
c = B("c")

f.s = b
b.z = f
b.r = c
c.z = f
c.r = b
assert c.z.s.r.txt == "c"