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

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

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

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

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

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

b.w = a
n.w = b
a.w = b
assert n.w.w.w.txt == "b"