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

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

class C:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

e = A("e")
i = B("i")
g = C("g")
d = B("d")

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

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

class C:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

e = A("e")
i = B("i")
g = C("g")
d = B("d")

e.w = d
i.z = d
i.o = e
g.w = i
d.z = i
d.o = e
assert e.w.z.o.w.txt == "d"