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

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

n = A("n")
h = B("h")
e = A("e")
i = A("i")
g = A("g")
c = A("c")
m = A("m")
b = A("b")
d = B("d")
l = A("l")

n.r = d
h.u = g
e.r = h
i.r = d
g.r = d
c.r = h
m.r = h
b.r = h
d.u = c
l.r = d
assert b.r.u.r.u.r.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

n = A("n")
h = B("h")
e = A("e")
i = A("i")
g = A("g")
c = A("c")
m = A("m")
b = A("b")
d = B("d")
l = A("l")

n.r = d
h.u = g
e.r = h
i.r = d
g.r = d
c.r = h
m.r = h
b.r = h
d.u = c
l.r = d
assert b.r.u.r.u.r.u.r.u.txt == "c"