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

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

l = A("l")
f = B("f")
j = A("j")
b = A("b")
g = B("g")
k = A("k")

l.w = j
f.s = l
f.q = k
j.w = k
b.w = j
g.s = l
g.q = j
k.w = b
assert k.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.s: A = None
        self.q: A = None
        self.txt = txt

l = A("l")
f = B("f")
j = A("j")
b = A("b")
g = B("g")
k = A("k")

l.w = j
f.s = l
f.q = k
j.w = k
b.w = j
g.s = l
g.q = j
k.w = b
assert k.w.w.w.w.w.w.txt == "k"