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

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

f = A("f")
l = B("l")
m = A("m")
j = A("j")

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

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

f = A("f")
l = B("l")
m = A("m")
j = A("j")

f.o = j
l.w = j
l.s = j
m.o = f
j.o = f
assert f.o.o.o.txt == "j"