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

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

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

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

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

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

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