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

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

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

f.x = c
d.w = f
c.w = f
assert c.w.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

f.x = c
d.w = f
c.w = f
assert c.w.x.w.txt == "f"