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

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

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

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

a.q = k
m.o = a
m.u = b
g.s = m
g.u = k
g.p = i
k.q = a
b.s = m
b.u = a
b.p = a
i.q = a
j.s = m
j.u = k
j.p = i
n.s = m
n.u = a
n.p = k
assert m.o.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

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

a.q = k
m.o = a
m.u = b
g.s = m
g.u = k
g.p = i
k.q = a
b.s = m
b.u = a
b.p = a
i.q = a
j.s = m
j.u = k
j.p = i
n.s = m
n.u = a
n.p = k
assert m.o.q.q.q.q.txt == "a"