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

f = A("f")
h = B("h")
n = B("n")
a = A("a")
b = B("b")
j = A("j")
i = B("i")
d = A("d")
e = A("e")
m = A("m")

f.s = j
h.q = n
n.q = h
a.s = j
b.q = i
j.s = a
i.q = n
d.s = m
e.s = m
m.s = j
assert b.q.q.q.q.q.q.q.q.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

f = A("f")
h = B("h")
n = B("n")
a = A("a")
b = B("b")
j = A("j")
i = B("i")
d = A("d")
e = A("e")
m = A("m")

f.s = j
h.q = n
n.q = h
a.s = j
b.q = i
j.s = a
i.q = n
d.s = m
e.s = m
m.s = j
assert b.q.q.q.q.q.q.q.q.txt == "n"