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

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

f = A("f")
i = B("i")
m = B("m")
k = B("k")

f.s = i
i.r = f
i.s = f
m.r = f
m.s = f
k.r = f
k.s = f
assert m.r.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.r: A = None
        self.s: A = None
        self.txt = txt

f = A("f")
i = B("i")
m = B("m")
k = B("k")

f.s = i
i.r = f
i.s = f
m.r = f
m.s = f
k.r = f
k.s = f
assert m.r.s.r.txt == "f"