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

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

a = A("a")
f = B("f")
g = A("g")
l = A("l")
i = B("i")
b = A("b")
c = A("c")
e = B("e")

a.w = g
f.q = l
g.w = a
l.w = c
i.q = c
b.w = g
c.w = l
e.q = a
assert l.w.w.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

a = A("a")
f = B("f")
g = A("g")
l = A("l")
i = B("i")
b = A("b")
c = A("c")
e = B("e")

a.w = g
f.q = l
g.w = a
l.w = c
i.q = c
b.w = g
c.w = l
e.q = a
assert l.w.w.w.w.w.w.w.w.txt == "l"