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

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

c = A("c")
n = B("n")
m = B("m")
j = B("j")
l = A("l")
k = A("k")
a = B("a")
e = A("e")
d = A("d")
h = A("h")

c.z = n
c.s = h
n.q = k
m.q = c
j.q = l
l.z = a
l.s = k
k.z = j
k.s = l
a.q = c
e.z = n
e.s = l
d.z = a
d.s = h
h.z = m
h.s = e
assert n.q.s.s.s.z.q.s.s.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.s: A = None
        self.txt = txt

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

c = A("c")
n = B("n")
m = B("m")
j = B("j")
l = A("l")
k = A("k")
a = B("a")
e = A("e")
d = A("d")
h = A("h")

c.z = n
c.s = h
n.q = k
m.q = c
j.q = l
l.z = a
l.s = k
k.z = j
k.s = l
a.q = c
e.z = n
e.s = l
d.z = a
d.s = h
h.z = m
h.s = e
assert n.q.s.s.s.z.q.s.s.z.q.txt == "k"