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

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

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

b.s = d
b.z = d
d.o = f
f.s = d
f.z = d
assert d.o.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.z: B = None
        self.txt = txt

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

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

b.s = d
b.z = d
d.o = f
f.s = d
f.z = d
assert d.o.z.o.txt == "f"