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

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

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

k = A("k")
n = B("n")
h = C("h")
c = B("c")
l = B("l")
m = B("m")
g = A("g")
b = B("b")
i = B("i")
a = A("a")

k.p = h
k.q = m
n.u = h
n.x = a
n.y = g
h.x = g
h.z = g
c.u = h
c.x = k
c.y = g
l.u = h
l.x = a
l.y = k
m.u = h
m.x = k
m.y = a
g.p = h
g.q = l
b.u = h
b.x = g
b.y = k
i.u = h
i.x = a
i.y = a
a.p = h
a.q = i
assert m.y.p.z.q.u.z.q.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: B = None
        self.txt = txt

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

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

k = A("k")
n = B("n")
h = C("h")
c = B("c")
l = B("l")
m = B("m")
g = A("g")
b = B("b")
i = B("i")
a = A("a")

k.p = h
k.q = m
n.u = h
n.x = a
n.y = g
h.x = g
h.z = g
c.u = h
c.x = k
c.y = g
l.u = h
l.x = a
l.y = k
m.u = h
m.x = k
m.y = a
g.p = h
g.q = l
b.u = h
b.x = g
b.y = k
i.u = h
i.x = a
i.y = a
a.p = h
a.q = i
assert m.y.p.z.q.u.z.q.u.z.txt == "g"