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

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

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

h = A("h")
k = B("k")
m = C("m")
f = A("f")
e = C("e")
i = A("i")

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

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

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

h = A("h")
k = B("k")
m = C("m")
f = A("f")
e = C("e")
i = A("i")

h.p = k
k.y = i
k.s = m
k.x = e
m.y = k
f.p = k
e.y = k
i.p = k
assert m.y.x.y.s.y.x.txt == "e"