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

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

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

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

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

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

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

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

c.s = d
d.z = c
m.y = c
m.w = d
assert d.z.s.z.txt == "c"