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

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

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

h = A("h")
a = B("a")
k = C("k")
j = A("j")
d = C("d")
m = B("m")
i = C("i")
l = B("l")
e = B("e")

h.y = j
a.p = m
a.y = h
k.v = h
j.y = h
d.v = h
m.p = e
m.y = h
i.v = j
l.p = m
l.y = h
e.p = a
e.y = h
assert k.v.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
k = C("k")
j = A("j")
d = C("d")
m = B("m")
i = C("i")
l = B("l")
e = B("e")

h.y = j
a.p = m
a.y = h
k.v = h
j.y = h
d.v = h
m.p = e
m.y = h
i.v = j
l.p = m
l.y = h
e.p = a
e.y = h
assert k.v.y.y.y.y.y.txt == "j"