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

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

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

h = A("h")
a = B("a")
k = C("k")
g = A("g")
m = A("m")
e = A("e")
n = B("n")

h.r = k
a.s = e
k.r = n
k.p = a
g.r = k
m.r = k
e.r = k
n.s = e
assert m.r.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
k = C("k")
g = A("g")
m = A("m")
e = A("e")
n = B("n")

h.r = k
a.s = e
k.r = n
k.p = a
g.r = k
m.r = k
e.r = k
n.s = e
assert m.r.r.s.r.txt == "k"