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

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

b = A("b")
f = B("f")
h = A("h")

b.o = h
f.s = b
h.o = b
assert f.s.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.s: A = None
        self.txt = txt

b = A("b")
f = B("f")
h = A("h")

b.o = h
f.s = b
h.o = b
assert f.s.o.o.txt == "b"