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

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

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

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

e.z = n
j.s = d
k.x = h
h.s = k
a.x = j
n.z = e
m.x = h
d.x = h
assert m.x.s.x.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

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

e.z = n
j.s = d
k.x = h
h.s = k
a.x = j
n.z = e
m.x = h
d.x = h
assert m.x.s.x.s.x.s.txt == "k"