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

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

a = A("a")
f = B("f")
b = B("b")
i = A("i")

a.w = i
f.r = b
f.x = i
b.r = f
b.x = i
i.w = a
assert i.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

a = A("a")
f = B("f")
b = B("b")
i = A("i")

a.w = i
f.r = b
f.x = i
b.r = f
b.x = i
i.w = a
assert i.w.w.w.txt == "a"