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

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

n = A("n")
k = B("k")
j = B("j")
g = B("g")
b = A("b")
h = B("h")
a = A("a")
c = A("c")
m = A("m")

n.q = b
n.z = c
k.w = m
k.t = n
j.w = m
j.t = m
g.w = n
g.t = m
b.q = n
b.z = n
h.w = m
h.t = m
a.q = m
a.z = c
c.q = a
c.z = n
m.q = b
m.z = a
assert a.z.q.q.z.q.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: A = None
        self.txt = txt

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

n = A("n")
k = B("k")
j = B("j")
g = B("g")
b = A("b")
h = B("h")
a = A("a")
c = A("c")
m = A("m")

n.q = b
n.z = c
k.w = m
k.t = n
j.w = m
j.t = m
g.w = n
g.t = m
b.q = n
b.z = n
h.w = m
h.t = m
a.q = m
a.z = c
c.q = a
c.z = n
m.q = b
m.z = a
assert a.z.q.q.z.q.z.z.txt == "c"