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

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

c = A("c")
h = B("h")
b = A("b")
a = A("a")
k = A("k")
n = B("n")
m = B("m")
j = A("j")
i = A("i")
f = A("f")

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

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

c = A("c")
h = B("h")
b = A("b")
a = A("a")
k = A("k")
n = B("n")
m = B("m")
j = A("j")
i = A("i")
f = A("f")

c.u = n
h.r = n
h.v = n
b.u = h
a.u = h
k.u = m
n.r = m
n.v = m
m.r = h
m.v = n
j.u = n
i.u = n
f.u = n
assert c.u.v.v.r.txt == "m"