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

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

n = A("n")
a = B("a")
l = A("l")
e = A("e")
j = B("j")
g = A("g")
h = B("h")

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

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

n = A("n")
a = B("a")
l = A("l")
e = A("e")
j = B("j")
g = A("g")
h = B("h")

n.s = a
n.w = j
a.q = h
l.s = j
l.w = h
e.s = j
e.w = a
j.q = a
g.s = j
g.w = j
h.q = j
assert a.q.q.q.q.q.q.txt == "a"