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

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

l = A("l")
k = B("k")
c = B("c")
j = B("j")
g = B("g")
h = B("h")
i = B("i")
b = B("b")
m = B("m")
f = B("f")

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

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

l = A("l")
k = B("k")
c = B("c")
j = B("j")
g = B("g")
h = B("h")
i = B("i")
b = B("b")
m = B("m")
f = B("f")

l.r = h
l.p = k
k.w = f
k.r = l
c.w = g
c.r = l
j.w = i
j.r = l
g.w = m
g.r = l
h.w = m
h.r = l
i.w = h
i.r = l
b.w = c
b.r = l
m.w = g
m.r = l
f.w = j
f.r = l
assert l.r.w.w.w.r.p.w.r.txt == "l"