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

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

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

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

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

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

e.o = f
f.z = d
n.o = f
d.o = f
assert d.o.z.o.z.txt == "d"