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

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

k = A("k")
m = B("m")
d = B("d")
g = A("g")
a = B("a")
n = A("n")
l = B("l")
b = A("b")
h = B("h")
c = A("c")

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

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

k = A("k")
m = B("m")
d = B("d")
g = A("g")
a = B("a")
n = A("n")
l = B("l")
b = A("b")
h = B("h")
c = A("c")

k.u = h
m.v = l
m.r = a
d.v = a
d.r = h
g.u = a
a.v = l
a.r = l
n.u = d
l.v = m
l.r = h
b.u = l
h.v = m
h.r = m
c.u = h
assert h.v.r.v.r.v.r.v.txt == "l"