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

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

m = A("m")
l = B("l")
c = A("c")
d = B("d")
e = B("e")

m.w = c
l.p = e
c.w = m
d.p = e
e.p = d
assert c.w.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: B = None
        self.txt = txt

m = A("m")
l = B("l")
c = A("c")
d = B("d")
e = B("e")

m.w = c
l.p = e
c.w = m
d.p = e
e.p = d
assert c.w.w.w.w.w.txt == "m"