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.txt = txt

f = A("f")
k = B("k")
h = B("h")

f.s = h
k.r = f
h.r = f
assert h.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.txt = txt

f = A("f")
k = B("k")
h = B("h")

f.s = h
k.r = f
h.r = f
assert h.r.s.r.txt == "f"