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

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

h = A("h")
k = B("k")
j = B("j")
e = B("e")
g = A("g")
n = A("n")
l = B("l")
d = A("d")
c = A("c")

h.q = k
k.u = e
j.u = l
e.u = l
g.q = k
n.q = e
l.u = k
d.q = l
c.q = k
assert g.q.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

h = A("h")
k = B("k")
j = B("j")
e = B("e")
g = A("g")
n = A("n")
l = B("l")
d = A("d")
c = A("c")

h.q = k
k.u = e
j.u = l
e.u = l
g.q = k
n.q = e
l.u = k
d.q = l
c.q = k
assert g.q.u.u.u.u.u.u.txt == "k"