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

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

k = A("k")
m = B("m")
a = B("a")
i = A("i")
e = A("e")
l = B("l")
h = A("h")

k.p = l
m.x = i
m.r = a
a.x = e
a.r = l
i.p = l
e.p = m
l.x = h
l.r = a
h.p = m
assert k.p.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

k = A("k")
m = B("m")
a = B("a")
i = A("i")
e = A("e")
l = B("l")
h = A("h")

k.p = l
m.x = i
m.r = a
a.x = e
a.r = l
i.p = l
e.p = m
l.x = h
l.r = a
h.p = m
assert k.p.r.r.r.r.txt == "l"