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

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

k = A("k")
j = B("j")
d = B("d")
b = B("b")
g = B("g")
e = B("e")
m = B("m")
i = B("i")

k.w = i
j.w = k
j.z = m
d.w = k
d.z = g
b.w = k
b.z = i
g.w = k
g.z = b
e.w = k
e.z = g
m.w = k
m.z = j
i.w = k
i.z = j
assert e.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

k = A("k")
j = B("j")
d = B("d")
b = B("b")
g = B("g")
e = B("e")
m = B("m")
i = B("i")

k.w = i
j.w = k
j.z = m
d.w = k
d.z = g
b.w = k
b.z = i
g.w = k
g.z = b
e.w = k
e.z = g
m.w = k
m.z = j
i.w = k
i.z = j
assert e.w.w.w.txt == "k"