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

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

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

j = A("j")
b = B("b")
i = C("i")
m = B("m")

j.s = i
b.s = j
i.r = j
m.s = j
assert j.s.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

j = A("j")
b = B("b")
i = C("i")
m = B("m")

j.s = i
b.s = j
i.r = j
m.s = j
assert j.s.r.s.r.txt == "j"