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

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

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

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

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

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

f.s = i
f.w = d
d.x = f
i.x = f
assert i.x.w.x.txt == "f"