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

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

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

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

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

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

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

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

h.u = g
h.z = g
h.p = b
k.p = i
k.q = b
k.s = b
b.p = k
a.u = k
a.z = m
a.p = b
c.u = k
c.z = k
c.p = b
i.u = g
i.z = m
i.p = b
g.p = h
g.q = b
g.s = b
m.p = i
m.q = b
m.s = b
d.p = a
d.q = b
d.s = b
assert b.p.q.p.q.p.s.p.txt == "k"