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

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

m = A("m")
b = B("b")
k = B("k")
h = A("h")
i = A("i")
f = A("f")
e = A("e")
n = A("n")
l = A("l")

m.z = i
b.w = k
b.s = m
k.w = b
k.s = f
h.z = n
i.z = n
f.z = m
e.z = h
n.z = h
l.z = f
assert m.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

m = A("m")
b = B("b")
k = B("k")
h = A("h")
i = A("i")
f = A("f")
e = A("e")
n = A("n")
l = A("l")

m.z = i
b.w = k
b.s = m
k.w = b
k.s = f
h.z = n
i.z = n
f.z = m
e.z = h
n.z = h
l.z = f
assert m.z.z.z.txt == "h"