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

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

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

n = A("n")
g = B("g")
d = C("d")
i = C("i")
b = C("b")
a = C("a")
m = A("m")
k = B("k")
h = A("h")

n.x = g
g.z = d
d.x = h
d.y = m
i.x = m
i.y = n
b.x = h
b.y = n
a.x = h
a.y = m
m.x = k
k.z = d
h.x = k
assert m.x.z.y.x.z.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

n = A("n")
g = B("g")
d = C("d")
i = C("i")
b = C("b")
a = C("a")
m = A("m")
k = B("k")
h = A("h")

n.x = g
g.z = d
d.x = h
d.y = m
i.x = m
i.y = n
b.x = h
b.y = n
a.x = h
a.y = m
m.x = k
k.z = d
h.x = k
assert m.x.z.y.x.z.y.x.txt == "k"