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

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

h = A("h")
c = B("c")
m = A("m")

h.w = m
c.v = m
m.w = h
assert h.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.v: A = None
        self.txt = txt

h = A("h")
c = B("c")
m = A("m")

h.w = m
c.v = m
m.w = h
assert h.w.w.w.txt == "m"