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

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

e = A("e")
j = B("j")
l = A("l")
m = A("m")
f = A("f")
k = A("k")
h = B("h")
b = A("b")
a = B("a")

e.q = f
j.s = e
l.q = b
m.q = f
f.q = l
k.q = e
h.s = k
b.q = l
a.s = f
assert e.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.s: A = None
        self.txt = txt

e = A("e")
j = B("j")
l = A("l")
m = A("m")
f = A("f")
k = A("k")
h = B("h")
b = A("b")
a = B("a")

e.q = f
j.s = e
l.q = b
m.q = f
f.q = l
k.q = e
h.s = k
b.q = l
a.s = f
assert e.q.q.q.q.q.q.q.txt == "b"