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

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

g = A("g")
f = B("f")
a = A("a")
i = A("i")
h = A("h")
k = A("k")
j = A("j")
d = B("d")
b = A("b")

g.w = h
f.z = b
f.q = i
a.w = b
i.w = g
h.w = k
k.w = b
j.w = a
d.z = b
d.q = j
b.w = h
assert a.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.z: A = None
        self.q: A = None
        self.txt = txt

g = A("g")
f = B("f")
a = A("a")
i = A("i")
h = A("h")
k = A("k")
j = A("j")
d = B("d")
b = A("b")

g.w = h
f.z = b
f.q = i
a.w = b
i.w = g
h.w = k
k.w = b
j.w = a
d.z = b
d.q = j
b.w = h
assert a.w.w.w.w.w.w.txt == "k"