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

g = A("g")
b = B("b")
d = A("d")
k = A("k")
c = B("c")
j = A("j")
l = A("l")
m = A("m")

g.w = k
b.q = l
d.w = g
k.w = g
c.q = k
j.w = k
l.w = k
m.w = k
assert c.q.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

g = A("g")
b = B("b")
d = A("d")
k = A("k")
c = B("c")
j = A("j")
l = A("l")
m = A("m")

g.w = k
b.q = l
d.w = g
k.w = g
c.q = k
j.w = k
l.w = k
m.w = k
assert c.q.w.w.w.w.w.w.txt == "k"