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

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

n = A("n")
f = B("f")
i = A("i")

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

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

n = A("n")
f = B("f")
i = A("i")

n.w = f
n.r = i
f.y = i
i.w = f
i.r = n
assert f.y.r.w.txt == "f"