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

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

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

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

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

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

b.r = g
b.u = g
m.p = j
m.w = b
c.r = h
c.u = m
d.r = m
d.u = g
e.r = m
e.u = g
f.r = m
f.u = h
j.r = m
j.u = g
h.p = b
h.w = c
g.p = d
g.w = b
assert c.u.p.u.w.r.w.r.w.txt == "b"