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

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

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

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

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

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

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

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

d.w = i
i.r = d
i.w = n
n.y = d
assert n.y.w.w.txt == "n"