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

g = A("g")
c = B("c")
b = B("b")
d = A("d")
i = A("i")
a = A("a")
n = B("n")
e = B("e")
j = A("j")
h = B("h")

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

g = A("g")
c = B("c")
b = B("b")
d = A("d")
i = A("i")
a = A("a")
n = B("n")
e = B("e")
j = A("j")
h = B("h")

g.s = i
c.q = b
b.q = h
d.s = i
i.s = j
a.s = d
n.q = h
e.q = n
j.s = g
h.q = n
assert b.q.q.q.q.q.q.txt == "n"