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

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

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

a.r = m
k.w = m
c.w = k
m.w = c
assert m.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

a.r = m
k.w = m
c.w = k
m.w = c
assert m.w.w.w.txt == "m"