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

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

m = A("m")
f = B("f")
h = B("h")
n = A("n")
e = B("e")
d = A("d")
a = B("a")
k = A("k")
i = B("i")
g = A("g")

m.o = e
m.w = d
f.w = k
f.z = i
h.w = n
h.z = f
n.o = i
n.w = g
e.w = m
e.z = i
d.o = f
d.w = k
a.w = g
a.z = h
k.o = e
k.w = g
i.w = d
i.z = a
g.o = h
g.w = m
assert m.w.w.w.w.o.z.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.w: A = None
        self.txt = txt

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

m = A("m")
f = B("f")
h = B("h")
n = A("n")
e = B("e")
d = A("d")
a = B("a")
k = A("k")
i = B("i")
g = A("g")

m.o = e
m.w = d
f.w = k
f.z = i
h.w = n
h.z = f
n.o = i
n.w = g
e.w = m
e.z = i
d.o = f
d.w = k
a.w = g
a.z = h
k.o = e
k.w = g
i.w = d
i.z = a
g.o = h
g.w = m
assert m.w.w.w.w.o.z.w.w.w.txt == "g"