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

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

k = A("k")
j = B("j")
g = A("g")
m = A("m")
e = A("e")
a = B("a")
n = B("n")
i = A("i")

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

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

k = A("k")
j = B("j")
g = A("g")
m = A("m")
e = A("e")
a = B("a")
n = B("n")
i = A("i")

k.q = n
j.s = n
g.q = a
m.q = j
e.q = n
a.s = n
n.s = a
i.q = n
assert j.s.s.s.txt == "n"