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

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

n = A("n")
c = B("c")
m = A("m")
j = A("j")
d = A("d")
e = B("e")
i = B("i")
b = A("b")
f = A("f")
g = B("g")

n.q = c
c.z = i
m.q = g
j.q = c
d.q = i
e.z = i
i.z = c
b.q = i
f.q = e
g.z = e
assert g.z.z.z.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

n = A("n")
c = B("c")
m = A("m")
j = A("j")
d = A("d")
e = B("e")
i = B("i")
b = A("b")
f = A("f")
g = B("g")

n.q = c
c.z = i
m.q = g
j.q = c
d.q = i
e.z = i
i.z = c
b.q = i
f.q = e
g.z = e
assert g.z.z.z.z.z.z.z.z.z.txt == "c"