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

j = A("j")
n = B("n")
h = B("h")
g = B("g")
a = A("a")
i = A("i")
b = A("b")
l = A("l")
d = A("d")
m = B("m")

j.r = m
n.u = a
h.u = i
g.u = j
a.r = n
i.r = n
b.r = n
l.r = n
d.r = h
m.u = i
assert d.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

j = A("j")
n = B("n")
h = B("h")
g = B("g")
a = A("a")
i = A("i")
b = A("b")
l = A("l")
d = A("d")
m = B("m")

j.r = m
n.u = a
h.u = i
g.u = j
a.r = n
i.r = n
b.r = n
l.r = n
d.r = h
m.u = i
assert d.r.u.r.u.r.u.r.u.txt == "a"