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

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

f = A("f")
b = B("b")
m = B("m")
j = B("j")
a = A("a")

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

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

f = A("f")
b = B("b")
m = B("m")
j = B("j")
a = A("a")

f.w = a
b.o = m
b.s = f
m.o = b
m.s = f
j.o = b
j.s = f
a.w = f
assert f.w.w.w.w.txt == "f"