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.z: B = None
        self.txt = txt

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

d.o = e
b.w = d
b.z = f
f.w = e
f.z = b
e.o = d
assert d.o.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.z: B = None
        self.txt = txt

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

d.o = e
b.w = d
b.z = f
f.w = e
f.z = b
e.o = d
assert d.o.o.o.o.txt == "d"