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

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

n = A("n")
a = B("a")
j = A("j")
g = B("g")
b = A("b")
m = A("m")
l = B("l")
d = B("d")
c = B("c")
e = A("e")

n.q = e
a.v = m
j.q = b
g.v = m
b.q = j
m.q = b
l.v = b
d.v = b
c.v = n
e.q = j
assert m.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.v: A = None
        self.txt = txt

n = A("n")
a = B("a")
j = A("j")
g = B("g")
b = A("b")
m = A("m")
l = B("l")
d = B("d")
c = B("c")
e = A("e")

n.q = e
a.v = m
j.q = b
g.v = m
b.q = j
m.q = b
l.v = b
d.v = b
c.v = n
e.q = j
assert m.q.q.q.q.q.q.q.txt == "b"