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

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

b = A("b")
d = B("d")
e = A("e")

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

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

b = A("b")
d = B("d")
e = A("e")

b.s = d
d.x = b
e.s = d
assert e.s.x.s.txt == "d"