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

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

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

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

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

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

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

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

m.z = h
h.w = m
d.x = h
d.y = m
assert m.z.w.z.txt == "h"