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

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

k = A("k")
e = B("e")
n = A("n")
l = B("l")
f = B("f")
d = A("d")
h = B("h")
g = A("g")
a = A("a")
j = A("j")

k.q = a
e.x = k
n.q = d
l.x = g
f.x = a
d.q = j
h.x = j
g.q = d
a.q = j
j.q = g
assert h.x.q.q.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.x: A = None
        self.txt = txt

k = A("k")
e = B("e")
n = A("n")
l = B("l")
f = B("f")
d = A("d")
h = B("h")
g = A("g")
a = A("a")
j = A("j")

k.q = a
e.x = k
n.q = d
l.x = g
f.x = a
d.q = j
h.x = j
g.q = d
a.q = j
j.q = g
assert h.x.q.q.q.q.q.q.q.q.q.txt == "j"