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

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

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

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

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

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

m.w = c
e.p = m
c.p = m
k.w = e
assert e.p.w.p.txt == "m"