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

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

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

n = A("n")
f = B("f")
h = C("h")

n.z = f
f.w = h
h.r = f
assert n.z.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

n = A("n")
f = B("f")
h = C("h")

n.z = f
f.w = h
h.r = f
assert n.z.w.r.txt == "f"