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

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

g = A("g")
n = B("n")
e = B("e")
j = B("j")
k = B("k")
l = B("l")
i = A("i")
m = A("m")
b = B("b")

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

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

g = A("g")
n = B("n")
e = B("e")
j = B("j")
k = B("k")
l = B("l")
i = A("i")
m = A("m")
b = B("b")

g.p = i
n.q = k
e.q = j
j.q = l
k.q = e
l.q = j
i.p = m
m.p = i
b.q = n
assert k.q.q.q.q.q.q.q.txt == "l"