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

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

g = A("g")
j = B("j")
n = B("n")
i = A("i")
b = B("b")
k = B("k")
f = B("f")
m = A("m")
l = A("l")

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

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

g = A("g")
j = B("j")
n = B("n")
i = A("i")
b = B("b")
k = B("k")
f = B("f")
m = A("m")
l = A("l")

g.z = i
j.q = n
j.z = k
n.q = j
n.z = f
i.z = m
b.q = f
b.z = k
k.q = f
k.z = f
f.q = b
f.z = k
m.z = g
l.z = i
assert m.z.z.z.z.z.z.z.z.z.txt == "m"