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

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

m = A("m")
i = B("i")
d = B("d")
b = B("b")
a = A("a")

m.x = a
m.w = d
i.o = m
d.o = a
b.o = m
a.x = m
a.w = i
assert i.o.x.x.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.w: B = None
        self.txt = txt

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

m = A("m")
i = B("i")
d = B("d")
b = B("b")
a = A("a")

m.x = a
m.w = d
i.o = m
d.o = a
b.o = m
a.x = m
a.w = i
assert i.o.x.x.w.o.txt == "a"