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

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

a = A("a")
m = B("m")
k = A("k")
b = A("b")

a.w = b
m.p = k
k.w = a
b.w = k
assert a.w.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.p: A = None
        self.txt = txt

a = A("a")
m = B("m")
k = A("k")
b = A("b")

a.w = b
m.p = k
k.w = a
b.w = k
assert a.w.w.w.w.txt == "b"