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

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

b = A("b")
l = B("l")
h = A("h")
a = B("a")
i = A("i")
d = B("d")
m = A("m")
k = B("k")
c = B("c")

b.r = i
l.p = k
l.y = h
h.r = i
a.p = k
a.y = m
i.r = h
d.p = l
d.y = i
m.r = h
k.p = l
k.y = b
c.p = a
c.y = b
assert m.r.r.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.p: B = None
        self.y: A = None
        self.txt = txt

b = A("b")
l = B("l")
h = A("h")
a = B("a")
i = A("i")
d = B("d")
m = A("m")
k = B("k")
c = B("c")

b.r = i
l.p = k
l.y = h
h.r = i
a.p = k
a.y = m
i.r = h
d.p = l
d.y = i
m.r = h
k.p = l
k.y = b
c.p = a
c.y = b
assert m.r.r.r.r.r.r.r.txt == "h"