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

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

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

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

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

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

a.x = i
a.q = i
j.q = g
k.q = j
l.q = m
i.x = a
i.q = a
m.q = g
g.q = b
e.q = m
b.q = k
assert g.q.q.q.q.q.q.q.q.q.txt == "b"