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

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

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

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

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

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

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

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

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