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

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

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

f = A("f")
m = B("m")
k = C("k")
j = A("j")
i = A("i")
g = A("g")
n = A("n")
h = C("h")
d = C("d")
c = C("c")

f.q = d
m.y = f
k.o = c
j.q = c
i.q = c
g.q = k
n.q = c
h.o = k
d.o = h
c.o = k
assert i.q.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

f = A("f")
m = B("m")
k = C("k")
j = A("j")
i = A("i")
g = A("g")
n = A("n")
h = C("h")
d = C("d")
c = C("c")

f.q = d
m.y = f
k.o = c
j.q = c
i.q = c
g.q = k
n.q = c
h.o = k
d.o = h
c.o = k
assert i.q.o.o.o.o.o.o.o.txt == "k"