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

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

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

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

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

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

l.x = m
l.w = m
n.p = m
n.w = l
m.p = n
m.w = l
assert m.p.p.w.txt == "l"