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

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

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

k = A("k")
n = B("n")
a = C("a")
d = C("d")
j = A("j")
i = B("i")
b = A("b")
m = B("m")
c = A("c")
f = A("f")

k.p = j
k.x = a
n.s = i
n.x = m
n.u = c
a.q = d
d.q = a
j.p = c
j.x = d
i.s = m
i.x = m
i.u = f
b.p = j
b.x = a
m.s = i
m.x = n
m.u = k
c.p = f
c.x = a
f.p = k
f.x = a
assert m.s.u.p.x.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.x: C = None
        self.txt = txt

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

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

k = A("k")
n = B("n")
a = C("a")
d = C("d")
j = A("j")
i = B("i")
b = A("b")
m = B("m")
c = A("c")
f = A("f")

k.p = j
k.x = a
n.s = i
n.x = m
n.u = c
a.q = d
d.q = a
j.p = c
j.x = d
i.s = m
i.x = m
i.u = f
b.p = j
b.x = a
m.s = i
m.x = n
m.u = k
c.p = f
c.x = a
f.p = k
f.x = a
assert m.s.u.p.x.q.q.q.q.q.txt == "d"