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

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

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

f.x = b
i.s = b
h.s = f
b.x = f
assert i.s.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

f.x = b
i.s = b
h.s = f
b.x = f
assert i.s.x.x.x.txt == "f"