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

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

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

h = A("h")
k = B("k")
m = C("m")
f = B("f")
d = C("d")
n = A("n")

h.y = f
h.u = f
h.z = d
k.q = h
k.z = m
k.r = d
m.v = f
f.q = n
f.z = m
f.r = m
d.v = f
n.y = f
n.u = f
n.z = m
assert h.z.v.z.v.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.z: C = None
        self.u: B = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
m = C("m")
f = B("f")
d = C("d")
n = A("n")

h.y = f
h.u = f
h.z = d
k.q = h
k.z = m
k.r = d
m.v = f
f.q = n
f.z = m
f.r = m
d.v = f
n.y = f
n.u = f
n.z = m
assert h.z.v.z.v.q.z.txt == "m"