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

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

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

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

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

k.p = c
c.r = h
i.p = c
m.p = h
h.r = c
d.p = c
assert d.p.r.r.r.txt == "h"