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

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

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

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

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

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

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

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

h.z = g
m.y = g
g.x = m
assert m.y.x.y.txt == "g"