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

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

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

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

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

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

c.x = m
e.o = m
e.w = m
m.o = e
m.w = e
d.o = e
d.w = e
assert m.w.o.w.txt == "e"