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

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

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

m = A("m")
e = B("e")
d = C("d")
l = C("l")
i = A("i")
j = A("j")
k = B("k")
g = A("g")
f = A("f")

m.q = k
e.y = m
e.q = k
e.p = d
d.q = k
l.q = e
i.q = e
j.q = k
k.y = j
k.q = e
k.p = l
g.q = e
f.q = e
assert g.q.q.y.q.q.q.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

m = A("m")
e = B("e")
d = C("d")
l = C("l")
i = A("i")
j = A("j")
k = B("k")
g = A("g")
f = A("f")

m.q = k
e.y = m
e.q = k
e.p = d
d.q = k
l.q = e
i.q = e
j.q = k
k.y = j
k.q = e
k.p = l
g.q = e
f.q = e
assert g.q.q.y.q.q.q.q.y.q.txt == "k"