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

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

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

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

m.q = k
m.p = l
k.q = a
k.v = m
l.p = k
n.p = k
a.q = k
a.p = l
g.p = k
b.p = k
i.p = k
assert i.p.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: C = None
        self.txt = txt

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

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

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

m.q = k
m.p = l
k.q = a
k.v = m
l.p = k
n.p = k
a.q = k
a.p = l
g.p = k
b.p = k
i.p = k
assert i.p.v.q.txt == "k"