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

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

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

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

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

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

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