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

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

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

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

d.r = g
d.u = h
d.y = m
h.q = d
h.s = m
m.y = i
m.p = d
m.z = h
g.r = i
g.u = h
g.y = m
i.r = g
i.u = h
i.y = m
assert m.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.u: B = None
        self.y: C = None
        self.txt = txt

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

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

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

d.r = g
d.u = h
d.y = m
h.q = d
h.s = m
m.y = i
m.p = d
m.z = h
g.r = i
g.u = h
g.y = m
i.r = g
i.u = h
i.y = m
assert m.y.y.y.y.txt == "m"