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

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

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

h = A("h")
c = B("c")
m = C("m")
d = C("d")
j = B("j")
b = C("b")
l = C("l")
a = C("a")

h.u = d
c.p = h
m.t = j
m.r = h
d.t = c
d.r = h
j.p = h
b.t = c
b.r = h
l.t = j
l.r = h
a.t = j
a.r = h
assert h.u.t.p.u.r.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

h = A("h")
c = B("c")
m = C("m")
d = C("d")
j = B("j")
b = C("b")
l = C("l")
a = C("a")

h.u = d
c.p = h
m.t = j
m.r = h
d.t = c
d.r = h
j.p = h
b.t = c
b.r = h
l.t = j
l.r = h
a.t = j
a.r = h
assert h.u.t.p.u.r.u.r.u.txt == "d"