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

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

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

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

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

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

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