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

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

j = A("j")
e = B("e")
g = A("g")

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

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

j = A("j")
e = B("e")
g = A("g")

j.s = e
e.w = j
g.s = e
assert g.s.w.s.txt == "e"