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

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

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

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

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

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

f.s = h
c.x = e
c.o = b
h.x = e
h.o = b
b.x = f
b.o = c
e.s = c
assert e.s.o.x.txt == "f"