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

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

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

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

k.p = m
k.v = d
n.v = i
h.u = f
h.y = k
f.u = a
f.y = k
a.u = f
a.y = k
m.v = n
i.v = m
d.p = i
d.v = k
assert a.y.v.v.v.v.v.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: A = None
        self.txt = txt

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

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

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

k.p = m
k.v = d
n.v = i
h.u = f
h.y = k
f.u = a
f.y = k
a.u = f
a.y = k
m.v = n
i.v = m
d.p = i
d.v = k
assert a.y.v.v.v.v.v.p.v.txt == "m"