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

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

g = A("g")
h = B("h")
l = A("l")
i = B("i")
f = B("f")
b = B("b")
e = A("e")
n = A("n")
d = B("d")
j = B("j")

g.q = l
h.s = d
h.q = i
l.q = g
i.s = j
i.q = b
f.s = i
f.q = i
b.s = j
b.q = i
e.q = n
n.q = e
d.s = f
d.q = j
j.s = i
j.q = b
assert l.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.s: B = None
        self.q: B = None
        self.txt = txt

g = A("g")
h = B("h")
l = A("l")
i = B("i")
f = B("f")
b = B("b")
e = A("e")
n = A("n")
d = B("d")
j = B("j")

g.q = l
h.s = d
h.q = i
l.q = g
i.s = j
i.q = b
f.s = i
f.q = i
b.s = j
b.q = i
e.q = n
n.q = e
d.s = f
d.q = j
j.s = i
j.q = b
assert l.q.q.q.q.q.q.txt == "l"