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

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

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

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

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

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

d.o = c
d.s = m
m.o = i
m.w = d
c.o = d
c.s = i
i.o = m
i.w = d
assert i.w.s.o.w.txt == "d"