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

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

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

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

c.o = g
c.q = l
n.p = b
n.s = f
g.q = c
m.o = a
m.q = g
b.p = n
b.s = f
l.q = m
i.o = a
i.q = g
a.q = c
f.o = a
f.q = a
assert g.q.q.q.q.q.o.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.q: C = None
        self.txt = txt

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

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

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

c.o = g
c.q = l
n.p = b
n.s = f
g.q = c
m.o = a
m.q = g
b.p = n
b.s = f
l.q = m
i.o = a
i.q = g
a.q = c
f.o = a
f.q = a
assert g.q.q.q.q.q.o.q.q.txt == "l"