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

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

a = A("a")
j = B("j")
e = B("e")
f = B("f")

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

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

a = A("a")
j = B("j")
e = B("e")
f = B("f")

a.x = j
j.s = f
j.w = a
e.s = j
e.w = a
f.s = e
f.w = a
assert a.x.w.x.txt == "j"