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

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

f = A("f")
k = B("k")
b = B("b")
m = B("m")
j = B("j")
n = A("n")
g = A("g")
l = B("l")
e = A("e")
h = B("h")

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

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

f = A("f")
k = B("k")
b = B("b")
m = B("m")
j = B("j")
n = A("n")
g = A("g")
l = B("l")
e = A("e")
h = B("h")

f.r = n
k.u = f
k.w = g
b.u = f
b.w = g
m.u = n
m.w = g
j.u = e
j.w = e
n.r = f
g.r = n
l.u = e
l.w = n
e.r = f
h.u = f
h.w = e
assert b.u.r.r.r.r.r.txt == "n"