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

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

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

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

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

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

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