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

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

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

h = A("h")
d = B("d")
a = C("a")
k = C("k")
n = A("n")
e = A("e")

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

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

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

h = A("h")
d = B("d")
a = C("a")
k = C("k")
n = A("n")
e = A("e")

h.u = d
h.p = d
d.u = e
a.y = e
a.u = d
k.y = n
k.u = d
n.u = d
n.p = d
e.u = d
e.p = d
assert h.u.u.p.u.p.u.txt == "e"