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

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

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

d = A("d")
c = B("c")
b = C("b")
a = C("a")

d.y = b
d.r = b
c.z = b
b.r = a
b.y = a
b.w = c
a.r = b
a.y = b
a.w = c
assert c.z.w.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.r: C = None
        self.txt = txt

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

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

d = A("d")
c = B("c")
b = C("b")
a = C("a")

d.y = b
d.r = b
c.z = b
b.r = a
b.y = a
b.w = c
a.r = b
a.y = b
a.w = c
assert c.z.w.z.y.txt == "a"