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

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

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

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

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

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

l.o = m
l.x = m
m.p = l
b.o = m
b.x = m
assert l.x.p.x.txt == "m"