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

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

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

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

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

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

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