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

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

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

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

m.r = g
h.s = g
h.w = g
g.q = h
g.z = h
assert m.r.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

m.r = g
h.s = g
h.w = g
g.q = h
g.z = h
assert m.r.z.w.txt == "g"