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

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

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

n = A("n")
m = B("m")
d = C("d")
f = C("f")
j = C("j")
b = C("b")
k = C("k")
c = A("c")
a = C("a")
g = B("g")

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

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

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

n = A("n")
m = B("m")
d = C("d")
f = C("f")
j = C("j")
b = C("b")
k = C("k")
c = A("c")
a = C("a")
g = B("g")

n.x = j
m.q = c
d.o = n
f.o = c
j.o = c
b.o = c
k.o = n
c.x = f
a.o = c
g.q = c
assert f.o.x.o.x.o.x.o.x.o.x.txt == "f"