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

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

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

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

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

i.q = n
d.q = g
b.q = l
e.q = g
f.q = k
n.q = i
l.q = n
g.q = k
k.q = d
assert b.q.q.q.q.q.q.txt == "n"