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

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

b = A("b")
j = B("j")
a = B("a")

b.w = a
j.s = b
a.s = b
assert a.s.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

b = A("b")
j = B("j")
a = B("a")

b.w = a
j.s = b
a.s = b
assert a.s.w.s.txt == "b"