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

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

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

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

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

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

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

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

d.w = i
i.x = d
i.y = d
m.u = d
assert i.y.w.y.txt == "d"