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

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

b = A("b")
f = B("f")
a = B("a")
k = A("k")
j = B("j")
e = A("e")
h = A("h")
g = B("g")
d = A("d")
m = B("m")

b.u = e
f.u = e
f.r = g
a.u = k
a.r = g
k.u = h
j.u = d
j.r = m
e.u = h
h.u = e
g.u = d
g.r = a
d.u = b
m.u = k
m.r = a
assert g.r.u.u.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

b = A("b")
f = B("f")
a = B("a")
k = A("k")
j = B("j")
e = A("e")
h = A("h")
g = B("g")
d = A("d")
m = B("m")

b.u = e
f.u = e
f.r = g
a.u = k
a.r = g
k.u = h
j.u = d
j.r = m
e.u = h
h.u = e
g.u = d
g.r = a
d.u = b
m.u = k
m.r = a
assert g.r.u.u.u.u.u.u.u.u.txt == "h"