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

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

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

i = A("i")
d = B("d")
n = C("n")
c = C("c")
m = A("m")

i.w = d
d.o = c
n.y = c
n.o = d
c.y = n
c.o = d
m.w = d
assert i.w.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

i = A("i")
d = B("d")
n = C("n")
c = C("c")
m = A("m")

i.w = d
d.o = c
n.y = c
n.o = d
c.y = n
c.o = d
m.w = d
assert i.w.o.o.txt == "d"