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

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

i = A("i")
e = B("e")
m = B("m")
k = A("k")
h = A("h")
l = A("l")
g = A("g")
a = A("a")

i.q = h
e.p = k
m.p = h
k.q = h
h.q = g
l.q = k
g.q = k
a.q = l
assert a.q.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

i = A("i")
e = B("e")
m = B("m")
k = A("k")
h = A("h")
l = A("l")
g = A("g")
a = A("a")

i.q = h
e.p = k
m.p = h
k.q = h
h.q = g
l.q = k
g.q = k
a.q = l
assert a.q.q.q.q.q.q.q.txt == "g"