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

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

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

f.w = c
i.y = b
i.x = b
c.w = f
b.y = i
b.x = i
assert f.w.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.y: B = None
        self.x: B = None
        self.txt = txt

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

f.w = c
i.y = b
i.x = b
c.w = f
b.y = i
b.x = i
assert f.w.w.w.w.txt == "f"