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

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

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

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

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

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

f.r = h
h.y = f
c.r = h
assert f.r.y.r.txt == "h"