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

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

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

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

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

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

a.s = m
a.o = m
i.w = a
m.s = a
m.o = a
assert m.s.o.o.txt == "a"