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

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

k = A("k")
h = B("h")
b = B("b")
n = B("n")
m = B("m")
a = A("a")
i = B("i")

k.q = i
k.s = a
h.z = a
b.z = k
n.z = k
m.z = k
a.q = n
a.s = k
i.z = a
assert n.z.s.s.q.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: A = None
        self.txt = txt

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

k = A("k")
h = B("h")
b = B("b")
n = B("n")
m = B("m")
a = A("a")
i = B("i")

k.q = i
k.s = a
h.z = a
b.z = k
n.z = k
m.z = k
a.q = n
a.s = k
i.z = a
assert n.z.s.s.q.z.q.txt == "n"