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

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

k = A("k")
b = B("b")
i = A("i")
d = B("d")
c = B("c")
m = A("m")
n = A("n")
e = A("e")
j = B("j")
f = B("f")

k.s = i
b.q = d
i.s = n
d.q = j
c.q = j
m.s = n
n.s = i
e.s = k
j.q = d
f.q = c
assert i.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

k = A("k")
b = B("b")
i = A("i")
d = B("d")
c = B("c")
m = A("m")
n = A("n")
e = A("e")
j = B("j")
f = B("f")

k.s = i
b.q = d
i.s = n
d.q = j
c.q = j
m.s = n
n.s = i
e.s = k
j.q = d
f.q = c
assert i.s.s.s.s.s.txt == "n"