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

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

h = A("h")
l = B("l")
m = B("m")
c = A("c")
e = A("e")
b = A("b")
i = A("i")
a = B("a")
n = A("n")

h.t = e
h.q = l
l.p = a
m.p = l
c.t = h
c.q = m
e.t = b
e.q = m
b.t = n
b.q = a
i.t = e
i.q = m
a.p = l
n.t = b
n.q = l
assert e.t.q.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.q: B = None
        self.txt = txt

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

h = A("h")
l = B("l")
m = B("m")
c = A("c")
e = A("e")
b = A("b")
i = A("i")
a = B("a")
n = A("n")

h.t = e
h.q = l
l.p = a
m.p = l
c.t = h
c.q = m
e.t = b
e.q = m
b.t = n
b.q = a
i.t = e
i.q = m
a.p = l
n.t = b
n.q = l
assert e.t.q.p.p.p.p.p.p.txt == "a"