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

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

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

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

h.q = d
h.o = m
h.z = g
k.y = a
m.v = h
e.y = a
g.v = h
d.q = h
d.o = g
d.z = m
a.y = k
assert k.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: C = None
        self.z: C = None
        self.txt = txt

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

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

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

h.q = d
h.o = m
h.z = g
k.y = a
m.v = h
e.y = a
g.v = h
d.q = h
d.o = g
d.z = m
a.y = k
assert k.y.y.y.y.y.y.txt == "k"