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

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

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

j = A("j")
n = B("n")
h = C("h")
i = C("i")
l = C("l")
g = A("g")
k = A("k")

j.p = n
j.u = h
n.p = l
h.r = k
h.p = n
i.r = j
i.p = n
l.r = g
l.p = n
g.p = n
g.u = i
k.p = n
k.u = i
assert j.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.u: C = None
        self.txt = txt

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

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

j = A("j")
n = B("n")
h = C("h")
i = C("i")
l = C("l")
g = A("g")
k = A("k")

j.p = n
j.u = h
n.p = l
h.r = k
h.p = n
i.r = j
i.p = n
l.r = g
l.p = n
g.p = n
g.u = i
k.p = n
k.u = i
assert j.p.p.p.p.txt == "l"