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.t: A = None
        self.w: B = None
        self.txt = txt

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

a.s = f
a.o = f
m.t = a
m.w = i
f.s = a
f.o = a
i.t = f
i.w = m
assert a.o.o.o.s.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.t: A = None
        self.w: B = None
        self.txt = txt

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

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